-->
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: join and limits
PostPosted: Sun Jun 29, 2008 7:10 pm 
Newbie

Joined: Sun Jun 29, 2008 4:42 pm
Posts: 3
hi guys, i'm italian and i'm new in hibernate
i have a query and i would like that when i join two tables, the rows selected, of the set (or list) of the property of the class table which plays the role one-to-many, don't are selected all but i would like that are selected only a certain number of rows
for example:
Criteria crit = session.createCriteria(tbl1.class).setFetchMode("prop_rowsTbl2", FetchMode.JOIN)
in the property prop_rowsTbl2 for each row of tbl1 can i select only a certain number of rows of tbl2 when i join the tables on the query?
I hope that you have understood the question
thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 10:38 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
If you just want to limit the number of results, it's as simple as using the setFirstResult and setMaxresults methods of the Criteria object:

Code:
package com.examscam.criteria;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Example;
import com.examscam.HibernateUtil;
import com.examscam.model.User;

public class FindFirstFive {
public static void main(String args[]) {
  User user = new User();
  Session session = HibernateUtil.beginTransaction();
  Criteria criteria = session.createCriteria(User.class);
  criteria.setFirstResult(0);
  criteria.setMaxResults(5);
  List results = criteria.list();
  HibernateUtil.commitTransaction();
  for (int i = 0; i<results.size(); i++) {
    System.out.println(results.get(i).toString());
  }
}
}

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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.