-->
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: 3.0rc1 order by charset restrictions
PostPosted: Wed Mar 09, 2005 5:55 pm 
Newbie

Joined: Fri Oct 29, 2004 1:54 pm
Posts: 4
Location: Århus, Denmark
When migrating an application from Hibernate2 to Hibernate3, I was hit by the following diagnostic:

Caused by: line 1:99: unexpected char: '#'
at org.hibernate.hql.antlr.HqlBaseLexer.nextToken(HqlBaseLexer.java:278)
at antlr.TokenBuffer.fill(TokenBuffer.java:69)
at antlr.TokenBuffer.LA(TokenBuffer.java:80)
at antlr.LLkParser.LA(LLkParser.java:52)
at org.hibernate.hql.antlr.HqlBaseParser.identPrimary(HqlBaseParser.java:3297)
at org.hibernate.hql.antlr.HqlBaseParser.primaryExpression(HqlBaseParser.java:2906)
at org.hibernate.hql.antlr.HqlBaseParser.atom(HqlBaseParser.java:2784)
at org.hibernate.hql.antlr.HqlBaseParser.unaryExpression(HqlBaseParser.java:2665)
at org.hibernate.hql.antlr.HqlBaseParser.multiplyExpression(HqlBaseParser.java:2691)
at org.hibernate.hql.antlr.HqlBaseParser.additiveExpression(HqlBaseParser.java:532)
at org.hibernate.hql.antlr.HqlBaseParser.relationalExpression(HqlBaseParser.java:2112)
at org.hibernate.hql.antlr.HqlBaseParser.equalityExpression(HqlBaseParser.java:1975)
at org.hibernate.hql.antlr.HqlBaseParser.negatedExpression(HqlBaseParser.java:1938)


The query causing is
from EnumPatternLevel epl where epl.serialNo=:serialNo order by serial#, run_code, applicability_date, enum_group, ord

The problem is in the # sign in serial#.


Complaining about the # is new behaviour in Hibernate 3, but anyway I was always confused about the fact that the order by clause had to reference the actual column names and not the names of the attributes mapped to those columns (In the actual case the attribute serialNo is mapped to the column serial#).

As this is used with a 3rd party database I have no possibility of renaming the column.

- Erik


Top
 Profile  
 
 Post subject: Re: 3.0rc1 order by charset restrictions
PostPosted: Thu Mar 10, 2005 9:20 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
ebe wrote:
but anyway I was always confused about the fact that the order by clause had to reference the actual column names and not the names of the attributes mapped to those columns

???

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: 3.0rc1 order by charset restrictions
PostPosted: Fri Mar 11, 2005 8:43 am 
Newbie

Joined: Fri Oct 29, 2004 1:54 pm
Posts: 4
Location: Århus, Denmark
emmanuel wrote:
???


Maybe this part of my posting was too short to convey my question.

Anyway, I'll try again: The query in my original posting referenced an attribute in my Java object called serialNo that is mapped to the database column serial#. What has puzzled me in both Hibernate 2 and 3 is that when adding an 'order by' clause containing this attribute to the query, I have to refer to it via its column name and not via its mapped attribute name.

- Erik


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 11, 2005 8:53 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Of course you have to use the name of the property, not the column name.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 11, 2005 10:13 am 
Newbie

Joined: Fri Oct 29, 2004 1:54 pm
Posts: 4
Location: Århus, Denmark
michael wrote:
Of course you have to use the name of the property, not the column name.


Yes, that's how I think it should be, but if I change the query in my original posting to

return session.createQuery("from EnumPatternLevel epl where epl.serialNo=:serialNo order by serialNo, runCode, applicabilityDate, enumGroup, ord").
setInteger("serialNo", serialNo).
list();

i.e. by using the property names in the order by clause, I get:

Caused by: com.sybase.jdbc2.jdbc.SybSQLException: Invalid column name 'serialNo'.

at com.sybase.jdbc2.tds.Tds.processEed(Tds.java:2884)
at com.sybase.jdbc2.tds.Tds.nextResult(Tds.java:2206)
at com.sybase.jdbc2.jdbc.ResultGetter.nextResult(ResultGetter.java:69)
at com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybStatement.java:220)
at com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybStatement.java:203)
at com.sybase.jdbc2.jdbc.SybStatement.queryLoop(SybStatement.java:1596)
at com.sybase.jdbc2.jdbc.SybStatement.executeQuery(SybStatement.java:1581)
at com.sybase.jdbc2.jdbc.SybPreparedStatement.executeQuery(SybPreparedStatement.java:96)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:71)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:107)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1183)
at org.hibernate.loader.Loader.doQuery(Loader.java:363)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:203)
at org.hibernate.loader.Loader.doList(Loader.java:1499)
... 93 more


In Hibernate 2 I had to use the column names, but there the # in serial# was accepted.

Are we still discussing whether this is pilot error or are we getting close to submitting a bug report ?

- Erik


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 11, 2005 12:17 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You have to use order by epl.serialNo


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 11, 2005 12:40 pm 
Newbie

Joined: Fri Oct 29, 2004 1:54 pm
Posts: 4
Location: Århus, Denmark
michael wrote:
You have to use order by epl.serialNo


Genau -- so isst es. Vielen Dank, Michael.

- Erik


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 11, 2005 3:50 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Kein Problem :)


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.