Hibernate: Best way to fetch an association defined by a subclass

preview_player
Показать описание
EntityGraphs and JOIN FETCH clauses provide an easy and efficient way to fetch an entity and initialize its associations. But if you try to use it with a domain model that uses inheritance, you will quickly run into an issue:
You can’t use this approach in a polymorphic query to fetch an association that’s defined on a subclass. Or in other words, your JOIN FETCH clause or EntityGraph needs to reference an entity attribute that’s defined by your superclass. Otherwise, Hibernate will throw an exception because the attribute is unknown for some subclasses.
In this video, I will show you how to avoid this issue using your 1st level cache and multiple queries.

Like my channel? Subscribe!

Join the free Member Library:

Want to connect with me?

#Hibernate #associations #1stLevelCache
Рекомендации по теме
Комментарии
Автор

Hi what about querydsl. Will life be easier with less queries ?

ushak
Автор

Can you please make a series on rest api with a complete project.

-indeed