Monday, February 27, 2012

JPQL & Hibernate The data types varbinary and varchar are incompatible in the add operator

In a JPA/Hibernate app with a SQL Server database doing something like
LOWER(l.lastName) LIKE :lastName || '%'
will results in java.sql.SQLException: The data types varbinary and varchar are incompatible in the add operator if a null is passed into the parameter :lastName.

To work around this tell Hibernate that it really is a string by using one of the LOWER, UPPER, or other functions that return a String, like
LOWER(l.lastName) LIKE LOWER(:lastName) || '%'

No comments:

Post a Comment