-->
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.  [ 1 post ] 
Author Message
 Post subject: JPA: Query.setMaxResults() causes "Invalid column name"
PostPosted: Wed Oct 05, 2011 3:26 pm 
Newbie

Joined: Wed Oct 05, 2011 2:22 pm
Posts: 1
The following piece of code fails with a SQLServerException: Invalid column name 'x'.
Code:
                Query nativeQuery = entitiyManager.createNativeQuery("SELECT 1 AS X FROM EDIS_HOLD ORDER BY X");
                nativeQuery.setFirstResult(0);
                nativeQuery.setMaxResults(1);
                nativeQuery.getResultList();

The original statement is of course different, I have modified it to the simplest failing form.
If I remove the setMaxResults() it works fine.
The SQL statement issued by Hibernate is as follow:
Code:
WITH query AS (select ROW_NUMBER() OVER (order by x) as __hibernate_row_nr__, 1 as x from edis_hold ) SELECT * FROM query WHERE __hibernate_row_nr__ BETWEEN ? AND ?


Our code works with JBoss AS 6.0 (Hibernate core 3.0.6) but is broken in JBoss 6.1 (Hibernate 3.6.6).

The database is SQL Server 2008 R2.
I have tried with and without specifying the dialect (SQLServer2008Dialect).


Here is the stack trace:

Code:
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
   at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1215)
   at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1148)
   at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:255)
   ... my code is here ...
Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
   at org.hibernate.loader.Loader.doList(Loader.java:2536)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
   at org.hibernate.loader.Loader.list(Loader.java:2271)
   at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:316)
   at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1842)
   at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)
   at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:157)
   at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:246)
   ... 134 more
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid column name 'x'.
   at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197)
   at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1493)
   at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:390)
   at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:340)
   at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)
   at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)
   at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:179)
   at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:154)
   at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:283)
   at org.jboss.resource.adapter.jdbc.CachedPreparedStatement.executeQuery(CachedPreparedStatement.java:91)
   at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:342)
   at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
   at org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
   at org.hibernate.loader.Loader.doQuery(Loader.java:802)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
   at org.hibernate.loader.Loader.doList(Loader.java:2533)
   ... 141 more


It is hard to believe that I am the first one to encounter the problem but I haven't found anything similar on Google or in this forum.
Does anyone have a clue of what I am doing wrong or is it a bug without workaround?

Thanks,
-Cedric


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.