-->
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.  [ 2 posts ] 
Author Message
 Post subject: Limit size of property
PostPosted: Tue Dec 04, 2007 5:04 am 
Newbie

Joined: Tue Dec 04, 2007 4:53 am
Posts: 5
Hi,

I'm facing the following problem:

Class A owns a set (called "entries) and now I want to limit the size of the set when querying the Class. E.g. if the set has 20 entries in the database, I want to be able to retrieve only record 15 to 17. I tried it with the following, but the setFirstResult (and setMaxResults) applies for the class and not for the entries (as you see am using the Spring hibernatetemplate):


Code:
      
final List<A> list = getHibernateTemplate().executeFind(new HibernateCallback() {
         public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Criteria criteria = session.createCriteria(A.class, "a");
            
            Criteria subCriteria = criteria.createCriteria("a.entries"); // tried both "entries" and "a.entries"
            subCriteria.setFirstResult(first).setMaxResults(count);    // first and count are regular ints         

            return criteria.list();
         }
      });




thanks for your help!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 04, 2007 6:26 am 
Newbie

Joined: Tue Dec 04, 2007 4:53 am
Posts: 5
Alright, I got the mistake. The above query does work, it was just my fault to think that Hibernate only returns one row, what it does is to return "maxresults" rows which all contain the same ...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.