Home > Back-end >  ClassCastException: org.hibernate.loader.plan.build.internal.returns.CollectionReturnImpl cannot be
ClassCastException: org.hibernate.loader.plan.build.internal.returns.CollectionReturnImpl cannot be

Time:03-13

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;
}

CodePudding user response:

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

  • Related