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:
|