-->
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.  [ 4 posts ] 
Author Message
 Post subject: Sql server TOP or mysql LIMIT in a named query
PostPosted: Thu Mar 02, 2006 11:43 am 
Regular
Regular

Joined: Fri Nov 04, 2005 12:37 pm
Posts: 81
Is there any equivalent to LIMIT or TOP in HQL? As i need to use it in a named query such as the one in this mappying:



Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="vcf.code.entites.stats.Visit,vcf" table="vcfVisit">

      <id name="Id" column="id" type="Int32" unsaved-value="0">
         <generator class="native"/>
      </id>
      <property column="visited_id" type="Int32" name="VisitedCode" not-null="true" />
      <property column="visitor_code" type="Int32" name="VisitorCode" not-null="true" />
      <property column="timestamp" type="DateTime" name="Timestamp" not-null="true" />
      <property column="type" type="String" name="Type" not-null="true" length="1" />
      
   </class>
   
   <query name="Visit.GetLastest">top 1 from Visit where VisitorCode = ? order by timesstamp DESC</query>
   
</hibernate-mapping>


I need to use a named query i cannont use the querying objects.


Top
 Profile  
 
 Post subject: SetMaxResults
PostPosted: Fri Mar 03, 2006 12:50 am 
Regular
Regular

Joined: Tue Jan 03, 2006 7:21 am
Posts: 85
There is SetFirstResult and SetMaxResults methods in the IQuery interface which you can use to restrict the number of records returned by the Query. For your scenario remove the top 1 and execute the query as follows:

Code:
IQuery query = session.GetNamedQuery(XXX);
query.SetMaxResults = 1;
Object o = query.UniqueResult();


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 03, 2006 4:47 am 
Regular
Regular

Joined: Fri Nov 04, 2005 12:37 pm
Posts: 81
Thanks, but as i said i was asking if there is a way i can do this with just a named query ifself? without getting params on IQuery etc?


Top
 Profile  
 
 Post subject: Named Query
PostPosted: Fri Mar 03, 2006 5:04 am 
Regular
Regular

Joined: Tue Jan 03, 2006 7:21 am
Posts: 85
I do not think you can do this directly in the Named Query.


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