Meaningless Drivel is fun!
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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate eager fetching issue" Watch "Hibernate eager fetching issue" New topic

Hibernate eager fetching issue

RamandeepS Singh
Ranch Hand

Joined: Aug 25, 2009
Posts: 63


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

Ramandeep Singh
Samdani masum
Ranch Hand

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

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

Session ss = hibernateUtil.getSession();
Criteria crit = ss.createCriteria(Whatever.Class);
subject: Hibernate eager fetching issue
It's not a secret anymore!