-->
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: Named SQL Query, Query.setMaxResults, SQL Server 2000
PostPosted: Fri Jul 29, 2005 6:30 pm 
Newbie

Joined: Fri Jul 29, 2005 6:21 pm
Posts: 2
I have a full-text search query that I'm writing for SQL Server 2000. Since I need to use the CONTAINS operator, I decided to write a native SQL query. At the same time, I want to page through the results, so I am using the setMaxResults method of the Query object. My code looks like this -

Code:
Query query = sess.getNamedQuery(queryStr);
query.setMaxResults(pgSize);


What happens though, is the SQL Query created fails - the error message is -

Code:
18:06:42,953 ERROR [JDBCExceptionReporter] Incorrect syntax near the keyword 'top'.


And the statement generated by the log looks something like this -

Code:
top 26
        SELECT
           <some vars>
        FROM <some tables>
        WHERE <some condition>


The way SQL Server expects top to be used is something like

Code:
SELECT top (some stuff)


So I'm assuming Hibernate (version 2.x) is generating the wrong Statement. Am I stuck here? Or is there some workaround tht I haven't thought of?[/code]


Top
 Profile  
 
 Post subject: Re: Named SQL Query, Query.setMaxResults, SQL Server 2000
PostPosted: Fri Jul 29, 2005 8:31 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
bpapa wrote:
I have a full-text search query that I'm writing for SQL Server 2000. Since I need to use the CONTAINS operator, I decided to write a native SQL query. At the same time, I want to page through the results, so I am using the setMaxResults method of the Query object. My code looks like this -

Code:
Query query = sess.getNamedQuery(queryStr);
query.setMaxResults(pgSize);


What happens though, is the SQL Query created fails - the error message is -

Code:
18:06:42,953 ERROR [JDBCExceptionReporter] Incorrect syntax near the keyword 'top'.


And the statement generated by the log looks something like this -

Code:
top 26
        SELECT
           <some vars>
        FROM <some tables>
        WHERE <some condition>


The way SQL Server expects top to be used is something like

Code:
SELECT top (some stuff)


So I'm assuming Hibernate (version 2.x) is generating the wrong Statement. Am I stuck here? Or is there some workaround tht I haven't thought of?[/code]


What does your named-query mapping look like ?

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 8:36 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
The HB2 support for setMaxResults() was never designed to be used with native SQL queries.

However, you can easily create a custom dialect that will support this, by copying HB3.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.