Using 'like' operator on string-like column

We are migrating our code base from Hibernate 5 to 6.
Some of our entities have different types of columns that are treated as strings, for instance:

  • Enum annotated with @Enumerated(EnumType.STRING)
  • UserType (de)serializing to/from a string(VARCHAR) DB column (we plan to move these to use an AttributeConverter)

Then we have queries where we apply the “like” predicate on such a string-like field. While it used to work on Hibernate 5, as effectively the columns were saved/retrieved as strings, now it throws a ```
SemanticException saying that the operand is not a String.

How can we achieve a similar behavior on Hibernate 6?


I remember that this was recently fixed. Chances are that the latest 6.4 release contains the fix for this already.

Hi @pela, this sounds very similar to [HHH-17693] - Hibernate JIRA, though that issue was only about AttributeConverters it might have solved your problem too. The fix for is included in Hibernate version 6.4.4.Final, which is the latest release at time of writing. Could you please test with that and let us know if the issue persists?

I’ve got some contrasting results on 6.4.4.Final

  1. It works for both @Enumerated(EnumType.STRING) and custom type with AttributeConverter.
    For example, if I use a CriteriaQuery with predicates like"myEnum"), "%_A") or"customString"), "MY%")
  2. It does not work if I use a ParameterExpression as a parameter, throwing QueryArgumentException

Similarly with HQL query, it works unless I use binding parameters.

I’m also seeing that the reproducer project attached to HHH-17693 still fails after updating to 6.4.4.Final, throwing QueryArgumentException.


You’re right @pela, there seems to still be an issue with type validation when using a parameter expression in a like predicate involving a converted path. Could you please be so kind as to open a new followup Jira issue for that? We will look into it as soon as possible, thanks.

Thanks, I’ve raised [HHH-17790] - Hibernate JIRA

1 Like