-->
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.  [ 13 posts ] 
Author Message
 Post subject: Entity property 'when' causes syntax error in HQL
PostPosted: Tue Mar 15, 2005 2:52 am 
Beginner
Beginner

Joined: Tue Mar 15, 2005 2:36 am
Posts: 32
Location: Bonn, Germany
Hello,
I'm using H3-rc1 w/ EJB annotations with the following entity, where I already refactored the property from "when" to "when1" and specified the old column name to use an existing table:
Code:
@Entity(access = AccessType.FIELD)
public class Saying implements Serializable {

  @Id(generate = GeneratorType.AUTO)
  long id;

  String what;

  @Column(name="WHEN")
  long when1;

  @Column(length = 32, nullable = false)
  String who;

  // ...


I had problems with this query:
Code:
session.createQuery(
      // "from Saying as saying order by saying.id") // ok
      // "from Saying as saying order by saying.what desc") // ok
      // "from Saying as saying order by saying.who asc") // ok
          "from Saying as saying order by saying.when1 desc") // 'when' fails
          .list();


The log reports an "unexpected token: ." and doesn't generate any SQL statement.

Did I miss some docs? Is "when" a meta-word like "id"?

Cheers,
Christian

PS: Here is the logging output.

Quote:
Code:
2005-03-15 07:27:38,734 ERROR [main] ErrorCounter - *** ERROR: line 1:43: unexpected token: .
2005-03-15 07:27:38,750 WARN  [main] HqlParser - processEqualityExpression() : No expression to process!
Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxError: unexpected token: . near line 1, column 43 [from chat.Saying as saying order by saying.when desc]
   at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:74)
   at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:214)
   at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:127)
   at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
   at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:414)
   at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:814)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:773)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
   at chat.HibernatingChatServer.dumpAllSayings(HibernatingChatServer.java:134)
   at chat.HibernatingChatServer.start(HibernatingChatServer.java:187)
   at chat.HibernatingChatServer.main(HibernatingChatServer.java:91)
Caused by: line 1:43: unexpected token: .
   at org.hibernate.hql.antlr.HqlBaseParser.primaryExpression(HqlBaseParser.java:2922)
   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)
   at org.hibernate.hql.antlr.HqlBaseParser.logicalAndExpression(HqlBaseParser.java:1857)
   at org.hibernate.hql.antlr.HqlBaseParser.logicalOrExpression(HqlBaseParser.java:1821)
   at org.hibernate.hql.antlr.HqlBaseParser.expression(HqlBaseParser.java:1697)
   at org.hibernate.hql.antlr.HqlBaseParser.orderElement(HqlBaseParser.java:1655)
   at org.hibernate.hql.antlr.HqlBaseParser.orderByClause(HqlBaseParser.java:922)
   at org.hibernate.hql.antlr.HqlBaseParser.queryRule(HqlBaseParser.java:724)
   at org.hibernate.hql.antlr.HqlBaseParser.selectStatement(HqlBaseParser.java:227)
   at org.hibernate.hql.antlr.HqlBaseParser.statement(HqlBaseParser.java:150)
   at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:208)
   ... 9 more



Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 15, 2005 3:04 am 
Beginner
Beginner

Joined: Tue Mar 15, 2005 2:36 am
Posts: 32
Location: Bonn, Germany
This is the SQL generated by Hibernate using "when1" as the name:
Code:
Hibernate: select top ? saying0_.id as id, saying0_.what as what0_, saying0_.WHEN as WHEN0_, saying0_.who as who0_ from Saying saying0_ order by  saying0_.WHEN desc


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 15, 2005 6:55 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Well, this sounds perfectly fine to me, you have to use property names in the query ...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 15, 2005 7:05 am 
Beginner
Beginner

Joined: Tue Mar 15, 2005 2:36 am
Posts: 32
Location: Bonn, Germany
michael wrote:
Well, this sounds perfectly fine to me, you have to use property names in the query ...

Not to me, as it does not work with a property named when. I'll compose an unit test case for reproduction and attach it here. The properties "what", "who", "id" and "when1" do work as expected.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 15, 2005 7:17 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Ah okay, now I get what you mean ... If you can build a short, runnable testcase for this, submit it to JIRA please.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 15, 2005 7:24 am 
Beginner
Beginner

Joined: Tue Mar 15, 2005 2:36 am
Posts: 32
Location: Bonn, Germany
I'll submit a bug report to JIRA. Mhh... how do I "setup" a runnable test case w/o having configured a database?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 15, 2005 7:41 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Probably the easiest way (the way I usually do it) is to just add a unit test to the Hibernate Unit Test suite and submit that one.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 15, 2005 8:28 am 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
Sormuras wrote:
michael wrote:
Well, this sounds perfectly fine to me, you have to use property names in the query ...

Not to me, as it does not work with a property named when. I'll compose an unit test case for reproduction and attach it here. The properties "what", "who", "id" and "when1" do work as expected.


Can you add left and right to your list of property names as well ?

_________________
On the information super B road


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 15, 2005 8:33 am 
Contributor
Contributor

Joined: Thu Nov 06, 2003 9:49 pm
Posts: 104
Location: New York, NY
Sormuras wrote:
michael wrote:
Well, this sounds perfectly fine to me, you have to use property names in the query ...

Not to me, as it does not work with a property named when. I'll compose an unit test case for reproduction and attach it here. The properties "what", "who", "id" and "when1" do work as expected.


Currently, the first phase of the HQL query translator supports some keywords as identifiers in some contexts, but not 'where'. As you probably know that creates some interesting posibilities for ambiguity.

select where from where where where where.where = '3';

:)

Anyway, it's not a difficult thing to support if where is only used a property name.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 15, 2005 8:38 am 
Beginner
Beginner

Joined: Tue Mar 15, 2005 2:36 am
Posts: 32
Location: Bonn, Germany
Paul Newport wrote:
Can you add left and right to your list of property names as well?


...and 'center', 'bottom' and 'top' and and... No problem, I'll list'em all. :D

joshua wrote:
Currently, the first phase of the HQL query translator supports some keywords as identifiers in some contexts, but not 'where'. As you probably know that creates some interesting posibilities for ambiguity.


...and not 'when'? I'll add 'where' to the test list as well.

joshua wrote:
select where from where where where where.where = '3';


*hehe*

I'll leave 'where' alone.

Cheers,
Christian


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 15, 2005 11:54 am 
Beginner
Beginner

Joined: Tue Mar 15, 2005 2:36 am
Posts: 32
Location: Bonn, Germany
Minor update from here.

Checked out Hibernate3 head revision, called "build junitreport" and noticed a (small) bunch of warnings and errors in test.hql... anyway, added a property "long when;" to Animal.java (+xml) and inserted a parse statement in "HqlParsertTest#testOrderBy()" ... works w/ warnings.

As my entity depends on EJB annotations, which are not part of the main trunk, it is not an easy task to port my simple application to an automated test case. :(

Maybe, I'll pack a stripped and runnable version of my local test and submit it entirely to JIRA tonight.

(...)

I did some more refactorings against my code and tested

where -- prints a warning, but does not break w/ the exception from the initial posting
Code:
2005-03-15 15:17:02,359 WARN  [main] ErrorCounter - *** WARNING: Keyword  'where' is being intepreted as an identifier due to: expecting IDENT, found 'where'


left and right and then -- quit the show
Code:
2005-03-15 16:20:50,921 ERROR [main] ErrorCounter - *** ERROR: line 1:30: unexpected token: .
2005-03-15 16:20:50,921 WARN  [main] HqlParser - processEqualityExpression() : No expression to process!
Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxError: unexpected token: . near line 1, column 30 [from chat.Saying s order by s.left desc]
   at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:74)
   at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:214)
   at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:127)
   at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
   at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:414)
   at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:814)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:773)



Testing,
Christian

PS -- 'top' and 'bottom' and 'whenever' do work. :-)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 15, 2005 2:03 pm 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
Is there a convenient place where we can post HQL statements that break the new parser ?

I'm assuming we can just supply the HQL as a string rather than all the assoicated mapping files and objects etc ?

_________________
On the information super B road


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 18, 2005 2:55 am 
Beginner
Beginner

Joined: Tue Mar 15, 2005 2:36 am
Posts: 32
Location: Bonn, Germany
As I can't run my local tests at the moment, I'd like to know if the when is fixed in version 3.0.1. Is it?


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