-->
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: problem with group reserved word
PostPosted: Wed Mar 02, 2005 11:28 am 
Newbie

Joined: Wed Mar 02, 2005 9:05 am
Posts: 1
Hello!

Does anybody know how to deal with objects which have the same name as some SQL reserved keywords, like group. I have a Group object representing an academic group, but when I try to execute this query:

hbSession.createQuery(
"select group.name from Group as group")
.list());

the db server thinks of group as a reserved word.

In MySQL manual it is said to quote the reserved word, but when I do that, I receive another error about uknown alias 'group'.

Sorry, If I'm asking about the well known issue.

Thank you in advance,
--
Andrew Stepanenko,
Software engineer.

Hibernate version: 3.0 beta

Mapping documents:

Group.hbm.xml

<hibernate-mapping>
<class name="ua.edu.tane.ceis.unf.beans.Group" table="groups">
<id name="groupId" column="id" type="int" unsaved-value="null">
<generator class="increment"/>
</id>
<property name="name" column="name" type="string" length="20"/>
<property name="leader" column="leader" type="integer" length="4"/>
<property name="curator" column="curator" type="integer" length="11"/>
<property name="specialityShort" column="speciality_short" type="string" length="50"/>
<property name="specialityLong" column="speciality_long" type="string" length="255"/>
<property name="number" column="number" type="integer" length="11"/>
<property name="specialization" column="specialization" type="string" length="255"/>
<property name="institute" column="institute" type="string" length="100"/>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

ArrayList groups = (ArrayList)(hbSession.createQuery(
"select group.name from Group as group")
.list());

Full stack trace of any exception that occurs:

org.hibernate.QueryException: BY expected after GROUP or ORDER: group.name [select group.name from ua.edu.tane.ceis.unf.beans.Group as group]
org.hibernate.hql.classic.ClauseParser.token(ClauseParser.java:32)
org.hibernate.hql.classic.ClauseParser.end(ClauseParser.java:113)
org.hibernate.hql.classic.PreprocessingParser.end(PreprocessingParser.java:123)
org.hibernate.hql.classic.ParserHelper.parse(ParserHelper.java:30)
org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:172)
org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTransla

Name and version of the database you are using:
MySQL 4.1.7

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


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.