Can JPQL execute LIKE expressions against enums?
If I have an entity Foo with an enum field bar I can execute the following in MySQL(bar is stored as a MySQL enum)…
SELECT * FROM Foo WHERE `bar` LIKE '%SUFFIX'
However, the corresponding query in JPQL…
SELECT f FROM Foo f WHERE f.bar LIKE '%SUFFIX'
…complains that…
Parameter value [%SUFFIX] was not matching type [com.example.Foo$EnumType]
I don’t think it’s possible, the left part of a
LIKEis supposed to be a string_expression (in standard JPA). From the specification:And an enum_expression is not a string_expression.
The following would work though (using enum literals):
Another option would be to actually store the
barfield as aString(and to do some conversion from and to an enum in the getter/setter).Reference