You cannot set autocommit during a managed transaction
最近遇到一个头大的问题:把ejb部署到jobss5.0,其中持久层是hibernate3.2,然后在调用ejb时,老是报异常:
java.sql.SQLException: You cannot set autocommit during a managed transaction!
hibernate.cfg.xml配置如下:
<session-factory>
<property name="hibernate.connection.datasource">java:/my_datasource</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
<property name="hibernate.show_sql">false</property>
<property name="jdbc.batch_size">50</property>
<property name="hbm2ddl.auto">update</property>
<mapping resource="xxx/xxx/xxx/xxx.hbm.xml" />
......
</session-factory>
,后来看了下hibernate的相关文档,然后设置自动提交为false,在hibernate配置文件中加上:
<property name="hibernate.connection.autocommit">false</property>
<property name="hibernate.connection.release_mode ">auto</property>,还是不管用,很是郁闷了。
再说明下:打开session的方式是sessionFactory.openSession()
求救:这是肿么回事?????????
------解决方案--------------------
把 hibernate. 去掉 ,
hibernate.properties 属性文件里面 要用hibernate.
hibernate.cfg.xml配置文件里面 设置属性时 不要再属性名前面加上hibernate.
例如<property name="hibernate.connection.autocommit">false</property>
应该改成 <property name="connection.autocommit">false</property>
------解决方案--------------------
java.sql.
SQLException: You cannot set autocommit during a managed transaction!
去掉<property name="hibernate.connection.autocommit">false</property> 试试。