Answer the question
In order to leave comments, you need to log in
How to join tables in reverse order in a query using Criteria?
There are entities associated with the database: Film->Role->Actor. The Movie has a list of roles. The role has an actor. The actor does not know about films or roles. You can join all three tables like this (let's assume that only those films in which the actor Jon starred).
Criteria crit = session.createCriteria(Movie.class);
crit.createCriteria("roles", "r", JoinType.RIGHT_OUTER_JOIN);
crit.createCriteria("r.actor", "a", JoinType.RIGHT_OUTER_JOIN);
crit.add(Restrictions.eq("a.name","Jon"));
However, if I want a list of actors who played in 2005 movies, then I need something like
Criteria crit = session.createCriteria(Actor.class);
?
?
crit.add(Restrictions.eq("m.year",2005));
How to get these connections? The option to get movies through a request, and then get lists of roles (and then actors) from objects using the get method does not suit me.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question