@ManyToOne
@JoinColumn(name = "play_template_id", table = "team_play_mapping" )
public Play getPlay() {
return play;
}
public void setPlay( Play play ) {
this.play = play;
}
By default, this is eager loading. Can I get it so that it will read the play object from a cache without making it lazy loading? Am I correct that eager loading will force it to do a join query and hence no caching?
Eager loading and lazy loading are fetch strategies. Meaning that if you specify “eager” loading, it will do as few queries as possible, while if you specify “lazy” it will post pone the query for that object as much as possible (risking performing more queries). So, if you want something to be retrieved from the cache, you want a lazy loading strategy, ie: do not retrieve from the database unless necessary.
What you can try, however, is to apply a certain fetch profile based on which code is doing the query. For instance, at some point of the code, your query knows that it’s better to eager load Play, while later you know it’d be better to lazy load Play.
http://docs.jboss.org/hibernate/core/3.5/reference/en/html/performance.html#performance-fetching-profiles