I have an entity class that has a lazy field like this:
@Entity
public Movie implements Serializable {
...
@Basic(fetch = FetchType.LAZY)
private String story;
...
}
The story field should normally be loaded lazily because it's usually large. However sometimes, I need to load it eagerly, but I don't write something ugly like movie.getStory() to force the loading. For lazy relationship I know a fetch join can force a eager loading, but it doesn't work for lazy field. How do I write a query to eagerly load the story field?
I'd try Hibernate.initialize(movie)
. But calling the getter (and adding a comment that this forces initialization) is not that wrong.