Given a representation of database tables where two entities are connected through a join table, is it possible to sort on the other entity specifying the sort order somehow through annotations?
Consider, roughly, the following database tables:
actor ( id, name )
credit ( actorId, movieId, roleName )
movie ( id, title, year )
And hibernate entities like:
@Entity
class Actor {
@Id
Integer id;
@Column
String name;
@OneToMany
@JoinColumn(name = "actorId")
List<Credit> credits;
}
@Entity
class Credit {
@Column
String roleName;
@ManyToOne
@JoinColumn(name = "movieId")
Movie movie;
}
@Entity
class Movie {
@Id
Integer id;
@Column
Integer year;
@Column
String title;
}
So I'd like to be able to have the default sorting order return Credits for an Actor in descending order by the year of the movie:
actor.getCredits(); // Returns credits in order of Credit.movie.year
It seems like one level deep of joining is pretty straightforward to sort by using @OrderBy, for example @OrderBy("roleName") ... but how do I go another join deeper?
Thanks!