• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate eager fetching issue

 
RamandeepS Singh
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please give me complete model class then I shall give a solution for Eager fetching related data from orm .
 
Ibrahim Aziz
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following should solve your problem:

Session ss = hibernateUtil.getSession();
Criteria crit = ss.createCriteria(Whatever.Class);
crit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic