permaculture playing cards*
The moose likes Object Relational Mapping and the fly likes Hibernate eager fetching issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate eager fetching issue" Watch "Hibernate eager fetching issue" New topic
Author

Hibernate eager fetching issue

RamandeepS Singh
Ranch Hand

Joined: Aug 25, 2009
Posts: 63


Hi

I am newbie to hibernate

i have a self refrencing class user having one to many relation
i am using association table for one to many

i have 4 users having following records
1 abc
2 def
3 ghi
4 jkl

following records are there in association table
user child
1 2
1 3
1 4

when i am using lazy fetching and using criteria query to fetch user 1
its giving me 1 record and when i get childs its giving me 3 records that is working fine

BUT when i change it to eager
It is giving me thrice record 1

Thanks
Ramandeep Singh
Samdani masum
Greenhorn

Joined: Oct 10, 2010
Posts: 3
please give me complete model class then I shall give a solution for Eager fetching related data from orm .
Ibrahim Aziz
Greenhorn

Joined: Oct 17, 2011
Posts: 8
The following should solve your problem:

Session ss = hibernateUtil.getSession();
Criteria crit = ss.createCriteria(Whatever.Class);
crit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate eager fetching issue
 
Similar Threads
Hibernate POJOs -- association or no-association ?
Hibernate Association
Hibernate Association
Hibernate Mapping (Many-To-One Association). Problem. This forum is my last hope.
hibernate:many-to-many the association table is not getting populated