Migration Hibernate 6: SemanticException: Operand of 'like' is of type 'java.lang.Object' which is not a string

Any help is highly appreciated!

Hibernate 6 detect the result of unaccent as a Object and not a String, meaning that we can not do LIKE on it…

@Query(value = “SELECT myentity FROM MyEntity myentity WHERE unaccent(LOWER(myentity.name)) like CONCAT(‘%’, :name, ‘%’)”)
List searchByName(String search);

Spring boot 3.2 + postgresql-13.2-1

SemanticException: Operand of 'like' is of type 'java.lang.Object' which is not a string (it is not an instance of 'java.lang.String' or 'char[]')
SemanticException: Operand of 'like' is of type 'java.lang.Object' which is not a string (it is not an instance of 'java.lang.String' or 'char[]')

        ... 31 common frames omitted
Caused by: java.lang.IllegalArgumentException: org.hibernate.query.SemanticException: Operand of 'like' is of type 'java.lang.Object' which is not a string (it is not an instance of 'java.lang.String' or 'char[]')
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:143)
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:167)
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:173)
        at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:802)
        at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:707)
        at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:132)
        at jdk.internal.reflect.GeneratedMethodAccessor37.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:360)
        at jdk.proxy4/jdk.proxy4.$Proxy204.createQuery(Unknown Source)
        at org.springframework.data.jpa.repository.query.SimpleJpaQuery.validateQuery(SimpleJpaQuery.java:94)

1. List item

Save EditClose

Hibernate ORM does not know what the return type of this unknown function unaccent is and hence defaults to Object. You have two options:

  • Register the function with a FunctionContributor
  • Cast the result in the query e.g. ... WHERE cast(unaccent(...) as String) ...

Sorry for confusion, unaccent() was copied accidently from my working progress trial and error. Please discard

This is a pure JPA code without any function
The error is complaining about LIKE operand. I can use native query to go over the issue but I have tons of queries to change.

@Query(“SELECT i from Invoice i where lower(i.invoiceNumber) LIKE %:query%”)

SemanticException: Operand of ‘like’ is of type ‘java.lang.Object’ which is not a string (it is not an instance of ‘java.lang.String’ or ‘char’) , it looks like bug to me.

This seems like working
@Query("SELECT i from Invoice i join i.client c where "
+ " CAST(lower(i.invoiceNumber) as String) like %:query% "

Well, the query you posted is simply invalid. The proper syntax requires that you concatenate the % wildcard:

SELECT i from Invoice i join i.client c where lower(i.invoiceNumber) like '%' || :query || '%'