Hibernate, DB2, and executeQuery
If you're using DB2 with Hibernate make sure that the use_sql_comments Hibernate option is false.
I spent a good part of the day wondering why org.hibernate.Session.get() and org.hibernate.Query.uniqueResult() were failing because DB2 (v8.1) was throwing an exception saying "executeQuery method cannot be used for update".
I had set the use_sql_comments option to true in my Hibernate configuration file because I wanted to see the correlation between my HQL and the generated SQL. It appears that DB2's SQL parser checks the first word of the generated SQL to find out if it's an INSERT, UPDATE, DELETE, or SELECT. Since Hibernate puts the comment in front of the generated SQL the DB2 parser assumes that it's an update statement and throws an exception when Hibernate calls executeQuery().
I spent a good part of the day wondering why org.hibernate.Session.get() and org.hibernate.Query.uniqueResult() were failing because DB2 (v8.1) was throwing an exception saying "executeQuery method cannot be used for update".
I had set the use_sql_comments option to true in my Hibernate configuration file because I wanted to see the correlation between my HQL and the generated SQL. It appears that DB2's SQL parser checks the first word of the generated SQL to find out if it's an INSERT, UPDATE, DELETE, or SELECT. Since Hibernate puts the comment in front of the generated SQL the DB2 parser assumes that it's an update statement and throws an exception when Hibernate calls executeQuery().
