-
1. Re: Problem with FetchType.EAGER - multiple instances of an
kimbaltrue Nov 24, 2006 8:15 AM (in response to reubenf)I seem to be having the same problem, but with a OneToMany relationship.
I have a Parent object with a ManyToOne with a "classification" object which contains a list of attribute fields as a OneToMany relationship. Both of these joins are EAGER fetched.
What's interesting is that the duplication effect happens with a short list, of attributes but doesn't with a long list.
I'm using 4.0.5.GA, and EJB 3.0 persistence.
Example: Parent *<- Classification (or Typing object) ->* Attribute
Actual: Drawer *<- DrawerType ->* DrawerTrays
All EAGER Fetched -
2. Re: Problem with FetchType.EAGER - multiple instances of an
kimbaltrue Nov 24, 2006 8:48 AM (in response to reubenf)One interesting note is that I'm getting a multiple of 5 per record. So, if I have twelve (12) records I get back sixty (60) records and duplicates.
-
3. Re: Problem with FetchType.EAGER - multiple instances of an
kimbaltrue Nov 24, 2006 9:07 AM (in response to reubenf)It looks like this behavior isn't a bug (see quote from http://docs.jboss.org/ejb3/app-server/HibernateAnnotations/reference/en/html_single/index.html#d0e1046)
2.2.5.5. Association fetching
You have the ability to either eagerly or lazily fetch associated entities. The fetch parameter can be set to FetchType.LAZY or FetchType.EAGER. EAGER will try to use an outer join select to retrieve the associated object, while LAZY is the default and will only trigger a select when the associated object is accessed for the first time. EJBQL also has a fetch keyword that allows you to override laziness when doing a particular query. This is very useful to improve performance and is decided on a use case to use case basis.
It is very inconvenient though. I suppose there's no work around other than using LAZY Fetching.
However, should an outer join of a parent table to a sub-table using the parent's primary key result in duplicate records? I'll have to do this manually to see what's going on.