Let’s say I have entity MotionPicture with associations that look like this. MotionPictureEmployee and MotionPictureGenre are join entities. Code examples below
@OneToMany(
mappedBy = "motionPicture",
orphanRemoval = true,
fetch = FetchType.LAZY
)
private List<MotionPictureEmployee> employees = new ArrayList<>();
@OneToMany(
mappedBy = "motionPicture",
orphanRemoval = true,
fetch = FetchType.LAZY
)
private List<MotionPictureGenre> genres = new ArrayList<>();
Imagine more associations.. “tags”, “reviews”, etc.
Now, let’s say that we request a MotionPicture with genres + employees, another with genres + tags, another with all associations, so and so forth. How does Hibernate generally support these types of requests?
I’ve tried creating named entity graphs that are supplied as hints (dynamic approach), but I run into situations where these hints clash with my defined HQL (things like breaking my sql statements). I also considered creating a method for every combination but that just doesn’t seem reasonable.
What is the proper idiomatic way that Hibernate should and would approach this problem?