You cannot set autocommit during a managed transaction

goodlucktomyself 2012-05-12 11:33:47
最近遇到一个头大的问题:把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()
求救:这是肿么回事?????????
...全文
311 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
goodlucktomyself 2012-05-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
把 hibernate. 去掉 ,
hibernate.properties 属性文件里面 要用hibernate.

hibernate.cfg.xml配置文件里面 设置属性时 不要再属性名前面加上hibernate.

例如<property name="hibernate.connection.autocommit">false</property>
应该改成 <property……
[/Quote]
按照你这种方法试了下,也还是存在同样的问题,异常信息:
17:45:37,009 ERROR [SchemaUpdate] could not complete schema update
java.sql.SQLException: You cannot set autocommit during a managed transaction!
at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.setJdbcAutoCommit(BaseWrapperManagedConnection.java:598)
at org.jboss.resource.adapter.jdbc.WrappedConnection.setAutoCommit(WrappedConnection.java:458)
at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:36)
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:127)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:314)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1300)
at com.isw2.priorityclub.factory.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:31)
_jerrytiger 2012-05-14
  • 打赏
  • 举报
回复
java.sql.SQLException: You cannot set autocommit during a managed transaction!

去掉<property name="hibernate.connection.autocommit">false</property> 试试。
_jerrytiger 2012-05-12
  • 打赏
  • 举报
回复
把 hibernate. 去掉 ,
hibernate.properties 属性文件里面 要用hibernate.

hibernate.cfg.xml配置文件里面 设置属性时 不要再属性名前面加上hibernate.

例如<property name="hibernate.connection.autocommit">false</property>
应该改成 <property name="connection.autocommit">false</property>

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧