The comparison with < in this example is only to show that comparison operators (=, <, >, >=, <=, <>) do not work in this case.
In the example I use EnumType.ORDINAL, in the other case of EnumType EnumType.STRING a similar error occurs:
Error interpreting query [SELECT b FROM ItemB b WHERE b.type = 'B2']; this may indicate a semantic (user query) problem or a bug in the parser [SELECT b FROM ItemB b WHERE b.type = 'B2']
Can't compare test expression of type [BasicSqmPathSource(type : Enum)] with element of type [basicType@15(java.lang.String,12)]
The question is, why does it work with ItemA:
public interface ItemARepository extends JpaRepository<ItemA, Long>, JpaSpecificationExecutor<ItemA> {
@Query("SELECT a FROM ItemA a WHERE a.type < 1")
List<ItemA> findAllByTypeA2();
}
https://github.com/JGSteinke/hibernate-test/blob/main/src/main/java/de/hibernate/test/data/service/ItemARepository.java As I wrote before, it has only stopped working since the Hibernate update. My guess is that in case A the enum is compared depending on the EnumType (EnumType.ORDINAL as Integer or EnumType.STRING as String) and in case B this does not happen.
The question of sense of compare enums using < is not at issue here, but I would like to discuss it briefly. In this way you can, for example, find all entries that precede a certain status.
|