1、
在hibernate.cfg.xml配置如下,就不需要再代码中提交事务transaction.commit();
<!-- 是否自动提交事务 (只有insert自动提交)-->
<property name="hibernate.connection.autocommit">true</property>
2、
在代码中提交事务要取消
<!-- 是否自动提交事务 --> <property name="hibernate.connection.autocommit">true</property>
否则自动提交