-->
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: limiting results
PostPosted: Tue Jun 19, 2007 2:17 pm 
Newbie

Joined: Tue Jun 19, 2007 2:11 pm
Posts: 9
Hello,

I'm trying this:

String sql = "FROM myobject a WHERE a.var1 = ? AND a.var2 = ? LIMIT 1";
String[] params = new String[2];
params[0] = param1;
params[1] = param2;
List<myboject> result = this.getHibernateTemplate().find(sql, params);

but I gen an error saying that LIMIT was not identified. Is there another way to limit the number of rows in the result set using this method?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 19, 2007 6:40 pm 
Regular
Regular

Joined: Wed May 05, 2004 8:01 am
Posts: 53
you have to use hibernate callback:
Code:
public List<Event> getLastEvents( final Unit unit, final int count ) {
   return getHibernateTemplate().executeFind( new HibernateCallback() {
      public Object doInHibernate( Session session ) throws HibernateException, SQLException {
         Criteria c = session.createCriteria( Event.class );
         c.createCriteria( "unitConfig" ).add( Restrictions.eq(   "unit",
                                                   unit ) );
         c.addOrder( Order.desc( "date" ) );
         c.setMaxResults( count );
         return c.list();
      }
   } );
}

Please rate if that helped.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 20, 2007 9:41 am 
Newbie

Joined: Tue Jun 19, 2007 2:11 pm
Posts: 9
led me in the right direction, thanks


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.