-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Criteria Query - one-to-many associations
PostPosted: Tue Jan 22, 2008 12:40 pm 
Newbie

Joined: Tue Aug 21, 2007 12:36 am
Posts: 6
Hi,

Hibernate version:
hibernate-3.2.5.ga

Name and version of the database you are using:
Oracle 10g

We have a requirement where we need to get some specified number of records of main entity. The main entity has two one-to-many associations.

I have this criteria query:

Code:
Criteria cr = this.session.createCriteria(this.persistentClass).setFetchMode("asscoiation1", FetchMode.JOIN).setFetchMode("asscoiation2", FetchMode.JOIN).setFirstResult(0).setMaxResults(20);
List rows = cr.list();


Ideally I want above criteria to generate the query in such away that it fetches 20 main entities along with all their associations. The actual result set may be more than 20.

Can you please help me to modify the above criteria query so that it returns 20 main entities along with all their associations?

Thanks
Kamesh


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 22, 2008 2:47 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Code:
Criteria cr = this.session.createCriteria(this.persistentClass)
  .setFetchMode("asscoiation1", etchMode.JOIN)
  .setFetchMode("asscoiation2", FetchMode.JOIN)
  .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
  .setFirstResult(0).setMaxResults(20);
List rows = cr.list();

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 23, 2008 1:38 am 
Newbie

Joined: Tue Aug 21, 2007 12:36 am
Posts: 6
Thanks. That worked.

--Kamesh


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.