开发者

Hibernate error: executeQuery method cannot be used for update

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&开发者_如何学Cgt;
        <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>


  1. Try the full version - i.e. SELECT i FROM Intake i where i.assignedTo=?;
  2. If this doesn't work - upgrade the JDBC driver;
  3. If this doesn't work or there is no new version - file a bug for the JDBC driver.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜