With the update of Vaadin from version 14 to 24, Hibernate was also updated. In the process, I noticed a problem in the current Hibernate versions. Normally Vaadin 24 uses Hibernate 6.2.2.Final, but this version also has problems with generic types and I'm switching to 6.2.4.Final, that fixes it for another project. Now I found another issue in Hibernate also related to generic types. I have created a small Vaadin 24 project to illustrate the issue. This example can be found on GitHub: https://github.com/JGSteinke/hibernate-test I have created two classes ItemA and ItemB. ItemA uses an enum and ItemB extends AbstractItem. This uses a generic type which must be an enum. Now I want to use < with the enum field and a constant within an query. In the case of ItemA this is not a problem at all, but for ItemB I get the following exception: Can't compare test expression of type [BasicSqmPathSource(type : Enum)] with element of type [basicType@5(java.lang.Integer,4)] See following code snippets fore context. Actual sources are linked below.
@MappedSuperclass
public abstract class AbstractItem<T extends Enum<T>> extends AbstractEntity implements Item<T> {
@Enumerated(EnumType.ORDINAL)
@Column(name = "type", nullable = false)
protected T type;
@Override
public T getType() {
return type;
}
public void setType(T type) {
this.type = type;
}
}
https://github.com/JGSteinke/hibernate-test/blob/main/src/main/java/de/hibernate/test/data/entity/AbstractEntity.java
@Entity
@Table(name = "item_b")
public class ItemB extends AbstractItem<ItemB.Type> {
enum Type {
B1, B2, B3;
}
}
https://github.com/JGSteinke/hibernate-test/blob/main/src/main/java/de/hibernate/test/data/entity/ItemB.java
public interface ItemBRepository extends JpaRepository<ItemB, Long>, JpaSpecificationExecutor<ItemB> {
@Query("SELECT b FROM ItemB b WHERE b.type < 1")
List<ItemB> findAllByTypeB2();
}
https://github.com/JGSteinke/hibernate-test/blob/main/src/main/java/de/hibernate/test/data/service/ItemBRepository.java I use types like ItemB in many cases on Hibernate 5.1.0 without problems. |