-->
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: setMaxResults() and MS SQL Server 2005
PostPosted: Tue Jul 01, 2008 7:42 am 
Newbie

Joined: Tue Jul 01, 2008 7:30 am
Posts: 11
Location: Pune,India
Hi All,

Im using Hibernate 3 and MS SQL 2005.
here is a code :

Criteria criteria = session.createCriteria(ZipdataEntity.class)
.setProjection(Projections.distinct(Projections.projectionList()
.add(Projections.property("city"), "city")
.add(Projections.property("state"), "state")
.add(Projections.property("zipcode"), "zipcode")))


.addOrder(Order.desc("city"))
.setFirstResult(1)
.setMaxResults(10);

Here i want only top 10 results.
The query generated by hibernate is :
Hibernate: select distinct this_.CITY as y0_, this_.STATE as y1_, this_.ZIPCODE as y2_ from zipdata this_ order by y0_ desc limit ?, ?

and im getting an exception as :
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Line 1: Incorrect syntax near 'limit'.

please let me know is there a different way when we tackle with MS SQL Server 2005 and criteria.setMaxResults()
Note: im using JDBC driver for SQL Server 2005 only.
Thanks in advance.
--Sidh


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 02, 2008 2:27 am 
Newbie

Joined: Tue Jul 01, 2008 7:30 am
Posts: 11
Location: Pune,India
Hey i got the solution.
It was my mistake i havent set the dialect for SQL Server :(

Thanks:)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 11:05 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Sometimes the easiest problems are the toughest to fix.

Onwards and upwards!

_________________
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.  [ 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.