0

I'm trying the sample code in the document '1.5. First criteria query' section. The code is below,

CriteriaBuilder<Cat> cb = cbf.create(em, Cat.class, "c")
    .where("c.age").betweenExpression("5").andExpression("10")
    .where("SIZE(c.kittens)").geExpression("2")
    .orderByAsc("c.name")
    .orderByAsc("c.id");

And when I add the following code ClassCastException occurs.

List<Cat> results = cb.getResultList();

I created the github public repository, so you can check the code here.

Does anyone know where I am wrong?

I created the project with Spring Boot.

Any help would be appreciated. Thank you.

marthursson
  • 3,242
  • 1
  • 18
  • 28
ecormaksin
  • 19
  • 4

2 Answers2

0

add logs pls next time they are always helpful

I recommend u to run cb.getResultList() in debug and understand what comes

0

The problem is that your Cat entity has a kittens field which is not a plural attribute, but an integer. Change it to @OneToMany Set<Cat> kittens and the query will work. Unfortunately the problem is on the Hibernate side i.e. Hibernate does not print a proper error message but instead fails with the exception.

Christian Beikov
  • 15,141
  • 2
  • 32
  • 58