-->
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: How to limit the number of rows for composed object
PostPosted: Mon Oct 04, 2010 5:22 pm 
Newbie

Joined: Tue Sep 21, 2010 1:31 pm
Posts: 5
Hi: I have a many to many relationship like this

Class A {

set <B>
}

Class B {
Set <a>
}

I am in a situation where when I retrieve object B through Object A, I would like to have a limit on the composed object, that is object B. According to my understanding I can limit the number of rows for Object A by calling setMaxResults on the Query object, but I am not sure how can I limit the number of objects returned by the query for objectB. BTW I am using lazy evaluation so my code looks like this

List<ObjectA> result = session.createQuery("from ObjectA objectA where objectA.id = :id ").setParameter("id", id).list();
ObjectA objectA= result.get(0);

Set<ObjectB> seObjectB = ObjectA.getObjectB(); //Here I only want to return a limited number of rows instead of thousands of rows

Thanks,
RJ


Top
 Profile  
 
 Post subject: Re: How to limit the number of rows for composed object
PostPosted: Tue Oct 05, 2010 2:49 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
You can use a collection filter. There is an example (tenKittens) in the documentation http://docs.jboss.org/hibernate/stable/ ... -filtering


Top
 Profile  
 
 Post subject: Re: How to limit the number of rows for composed object
PostPosted: Tue Oct 05, 2010 12:15 pm 
Newbie

Joined: Tue Sep 21, 2010 1:31 pm
Posts: 5
Thanks for the help, it worked like a charm.

Regards,
RJ.


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.