Hibernate version: 3.0.1
Mapping documents:
Code:
<class name="Message">
<composite-id>
<key-property name="id" type="long">
<column name="message_id"/>
</key-property>
<key-many-to-one name="category"
column="category_id"
class="Category"/>
</composite-id>
<property name="text" type="string"/>
<many-to-one name="nextMessage" cascade="save-update" class="Message">
<column name="next_message_id"/>
<column name="next_message_category_id"/>
</many-to-one>
</class>
<class name="Category">
<id name="id" type="long" column="category_id">
<generator class="sequence">
<param name="sequence">sq_category</param>
</generator>
</id>
<property name="name" type="string"/>
<property name="description" type="string"/>
</class>
Code between sessionFactory.openSession() and session.close():Code:
// childMessage was just saved in a previous transaction,
// as the "take me to your leader" following "hello world"
Query query = session.createQuery(
"select m.nextMessage from Message m where m.nextMessage = :msg").setParameter("msg",
childMessage);
Message message = (Message) query.uniqueResult();
System.out.println(message == null ? "Failed!" : "Success");
Full stack trace of any exception that occurs:Code:
org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1525)
at org.hibernate.loader.Loader.list(Loader.java:1505)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:400)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:791)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:603)
at sandbox.Main.tryQuery(Main.java:129)
at sandbox.Main.run(Main.java:118)
at sandbox.Main.main(Main.java:77)
Caused by: java.sql.SQLException: Unexpected token: , in statement [select message1_.message_id as message1_, message1_.category_id as category2_, message1_.text as text0_, message1_.next_message_id as next4_0_, message1_.next_message_category_id as next5_0_ from Message message0_, Message message1_ where ((message0_.next_message_id, message0_.next_message_category_id)=? and message0_.next_message_id=message1_.message_id and message0_.next_message_category_id=message1_.category_id)]
at org.hsqldb.jdbc.jdbcUtil.throwError(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:379)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:320)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:86)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1096)
at org.hibernate.loader.Loader.doQuery(Loader.java:367)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:208)
at org.hibernate.loader.Loader.doList(Loader.java:1522)
... 9 more
Exception in thread "main"
Name and version of the database you are using: revision 2 of HSQLDB 1.7.3
The generated SQL (show_sql=true):Code:
Hibernate: select message1_.message_id as message1_, message1_.category_id as category2_, message1_.text as text0_, message1_.next_message_id as next4_0_, message1_.next_message_category_id as next5_0_ from Message message0_, Message message1_ where ((message0_.next_message_id, message0_.next_message_category_id)=? and message0_.next_message_id=message1_.message_id and message0_.next_message_category_id=message1_.category_id)
Debug level Hibernate log excerpt: