-->
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.  [ 8 posts ] 
Author Message
 Post subject: DB2 Order By Problem
PostPosted: Wed Mar 03, 2004 1:30 pm 
Newbie

Joined: Wed Feb 04, 2004 3:22 pm
Posts: 7
Location: Argentina
Hi, i have this query :

"from Aplicacion as a order by a.nombre"

when i try this query, i recive the following error (in Ibm DB2 7.1 UDB):

[IBM][CLI Driver][DB2/NT] SQL0104N An unexpected token "order" was found following "ICACION aplicacion0_". Expected tokens may include: "GROUP". SQLSTATE=42601

Sql :

select * from ( select rownumber() over(order by aplicacion0_.APLNOMBRE) as row_, aplicacion0_.APL_ID as APL_ID, aplicacion0_.APLNOMBRE as APLNOMBRE, aplicacion0_.DESC_APL as DESC_APL from APLICACION aplicacion0_ order by aplicacion0_.APLNOMBRE ) as temp_ where row_ between ?+1 and ?

Thank


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 1:51 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This is not the HQL that generate this SQL statement

_________________
Emmanuel


Top
 Profile  
 
 Post subject: DB2 Order by problem
PostPosted: Wed Mar 03, 2004 2:07 pm 
Newbie

Joined: Wed Feb 04, 2004 3:22 pm
Posts: 7
Location: Argentina
i try this :

Query q = HibernateSession.currentSession().createQuery("from Aplicacion as a order by a.nombre");
q.setFirstResult(2);
q.setMaxResults(2);
q.list();

the sql :

Hibernate: select * from ( select rownumber() over(order by aplicacion0_.APLNOMBRE) as row_, aplicacion0_.APL_ID as APL_ID, aplicacion0_.APLNOMBRE as APLNOMBRE, aplicacion0_.DESC_APL as DESC_APL from APLICACION aplicacion0_ order by aplicacion0_.APLNOMBRE ) as temp_ where row_ between ?+1 and ?

and the mapping :

<hibernate-mapping>

<class name="xxx.Aplicacion" table="APLICACION" dynamic-insert="true" dynamic-update="true">

<id name="id" type="long" column="APL_ID" unsaved-value="-1">
<generator class="native"/>
</id>

<property name="nombre">
<column name="APLNOMBRE" sql-type="varchar(50)"/>
</property>

<property name="descripcion">
<column name="DESC_APL" sql-type="varchar(50)"/>
</property>

....
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 2:56 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Might be an incompatibility with DB2 7 - try to get the query working directly by editing the SQL, and if you can, post again so the dialect can be adjusted (have no DB2 to test here)


Top
 Profile  
 
 Post subject: DB2 Order by problem
PostPosted: Wed Mar 03, 2004 4:03 pm 
Newbie

Joined: Wed Feb 04, 2004 3:22 pm
Posts: 7
Location: Argentina
The query without the second "order by" functions ok (check http://troels.arvin.dk/db/rdbms/ ) :

select * from (
select rownumber() over(order by aplicacion0_.APLNOMBRE) as row_,
aplicacion0_.APL_ID as APL_ID, aplicacion0_.APLNOMBRE as APLNOMBRE,
aplicacion0_.DESC_APL as DESC_APL from APLICACION aplicacion0_ ) as temp_
where row_ between 1 and 2

this query does not function :

select * from (
select
aplicacion0_.APL_ID as APL_ID,
aplicacion0_.APLNOMBRE as APLNOMBRE,
aplicacion0_.DESC_APL as DESC_APL
from APLICACION aplicacion0_
order by aplicacion0_.APLNOMBRE )
as temp_

Error: SQL0104N An unexpected token "order" was found following "ICACION aplicacion0_".
Expected tokens may include: "GROUP". SQLSTATE=42601
(State:42601, Native Code: FFFFFF98)

may be is something (bug) with an inner query with "order by" .

bye


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 4:12 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
And does it do the order? If yes, submit a JIRA entry.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 4:21 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Add it to JIRA please.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: DB2 Order by problem
PostPosted: Wed Mar 03, 2004 5:00 pm 
Newbie

Joined: Wed Feb 04, 2004 3:22 pm
Posts: 7
Location: Argentina
a quick and dirty patch to db2dialect:

...
StringBuffer pagingSelect = new StringBuffer( sql.length()+100 )
.append("select * from ( ")
// Patch here
.append(orderByIndex>0 ? sql.substring(0,orderByIndex) : sql)
// end patch
.insert( getAfterSelectInsertPoint(sql), rownumber.toString() )
.append(" ) as temp_ where row_ ");
...

bye


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