Hibernate 5.7 -> 6.2 causes org.hibernate.AnnotationException

Hi all. While preparing for Spring boot 2.7 → 3.1 migration (including Hibernate 5.7 → 6.2), we are struggling with a problem that seems difficult to solve.

Blame to us, we did not pay attention to the precautions while assigning @Inheritanced @Entity as target of @OneToMany; however the problem is that Hibernate 5 allows this, so at this point it causes a serious blocker in our migration plan.

So we are considering a miserable idea that recoding the infrastructure code related to JPA and we are wondering if there are anyone who are experiencing similar difficulties.

Error messages and entity definitions are in the attached gist link(https://gist.github.com/FrancescoJo/ca72628ee7be42b6f49d2f6b90dbfa26). Any advice would be great, so please let us know.

Thank you all for reading.

For reference, we read Migration Guide 3.0: Hibernate ORM 5 to 6 migration · quarkusio/quarkus Wiki · GitHub as well before migration work but we couldn’t find any related content. I believe that the part causing the problem is “4. Better determination of unnecessary joins (secondary tables, inheritance tables)” in the “Generated SQL” section, but it is difficult to determine the detailed cause.

It looks to me that it would be more appropriate to use @Inheritance(JOINED) for UserEntity and let BuyerEntity extends from UserEntity. The DB model would stay the same. If you don’t want that, you will have to define the @OneToMany association explicitly with @JoinColumn instead of relying on the mappedBy attribute.

Yes, you’re right.

What makes us miserable is, your opinion leads to same conclusion what we’ve made which could involve huge recodings, since since our persistent logic(which is wrong PoV of Hibernate 6.2) depends on the context that reads “creation of UserEntity and it should work solely by its own”, “UserEntity and BuyerEntity are different object”. Anyway, thank you for your kind reply!

1 Like