File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP 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