'ClassCastException: org.hibernate.loader.plan.build.internal.returns.CollectionReturnImpl cannot be cast to org.hibernate.loader.plan.spi.Fetch

I can not define what is wrong with my code. Last time I used it and it wordked, but now when I am trying to read User, I get ClassCast execption: java.lang.ClassCastException: org.hibernate.loader.plan.build.internal.returns.CollectionReturnImpl cannot be cast to org.hibernate.loader.plan.spi.Fetch

I am using Spring Boot and Hibernate, could you help to determine the reason. User object contains java.util.List of RoleEntity, which contains User in it.

Problem is in the second @Formula, first works, I don`t know what is wrong here.

@Formula("(SELECT COUNT(*) FROM rdb.review r WHERE r.entity_id = 
id)")
private Integer reviewsAmount;

@Formula("(SELECT COUNT(DISTINCT author_id) FROM rdb.review r WHERE 
r.entity_id = id)")
private Integer peopleEnvolved;
}


Solution 1:[1]

Answer is easy - I need to use r.author_id in second formula. But it works fine in MySQL Workbench, but does not work in @Formula

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 LisovIlya