boskonovic
boskonovic

Reputation: 125

overriding lazy fetch in OneToMany association

I've been facing the LazyInitializationException and had three solutions by googling it:

  1. add myList.size() in getMyList()
  2. override the lazy fetch (join fetch)
  3. eager fetch

i'm avoiding the eager fetching and was wondering what's the difference between eager fetching and join fetch. could anyone tell me what's the best solution?

Upvotes: 3

Views: 489

Answers (1)

Ryan Stewart
Ryan Stewart

Reputation: 128829

The best solution is likely one that you didn't list: the open session in view pattern. Spring provides a very convenient implementation of the pattern in the form of either a Servlet Filter or a method interceptor.

Eager fetching describes the laziness of a relationship, or when fetching happens. Join fetching describes the fetch strategy, or how fetching happens. The two are separate concepts. Section 21.1 of the Hibernate Reference Guide has a full description of the how and when bit along with a lot of other useful tidbits.

Upvotes: 2

Related Questions