When I run the following:
Session session = null;
Transaction tx = null;
List<Intake> intakes = null;
try{
session = sessionFactory.getCurrentSession();
tx = session.beginTransaction();
intakes = session.createQuery("from Intake i where i.assignedTo=?")
.setParameter(0, assignedTo).list();
tx.commit();
}
catch(HibernateException e){
tx.rollback();
logger.warn("Unable to list intakes for user " + assignedTo, e);
}
Hibernate always throws an exception and spits the following out to the console:
6406 [httpSSLWorkerThread-8080-1] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: -99999, SQLState: null
6406 [httpSSLWorkerThread-8080-1] ERROR org.hibernate.util.JDBCExceptionReporter - executeQuery method cannot be used for update.
Which is caused by:
Caused by: com.ibm.db2.jcc.a.SqlException: executeQuery method cannot be used for update.
at com.ibm.db2.jcc.a.hd.a(hd.java:2508)
at com.ibm.db2.jcc.a.id.d(id.java:1952)
at com.ibm.db2.jcc.a.id.X(id.java:505)
at com.ibm.db2.jcc.a.id.executeQuery(id.java:488)
Why is Hibernate giving me an error here whenfrom Intake i where i.assignedTo=?
is obviously not an update? I suspect it has something to do with the IBM DB2 JDBC Driver. I'm using DB2 Driver version 2.7.58.
Here is my Spring Hibernate configuration.
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>domain/Intake.hbm.xml</value>
<value>domain/Action.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.DB2Dialect
hibernate.current_session_context_class=thread
hibernate.cache.provider_class=org.hibernate.cache.NoCacheProvider
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.hbm2ddl.auto=create-drop
hibernate.use_sql_comments=true
</value>
</property>
</bean>