Does anybody know why I get this warning when I turn off the auto-commit in JPA configuration file?
Using this setting :
<property name="hibernate.connection.autocommit" value="false"/>
generates this warning :
2009-08-04 09:54:10,621 [main] WARN org.hibernate.ejb.Ejb3Configuration - hibernate.connection.autocommit = false break the EJB3 specification
How would this break EJB3 specification?
JPA and Hibernate connection monitoring – detecting the auto-commit mode. By default, a JDBC Connection is running in auto-commit mode, and to explicitly set the transaction boundaries, you need to disable the auto-commit mode via the setAutoCommit method and call commit or rollback at the end of the transaction.
autoCommit is a concept of JDBCConnection, which means "Transaction per statement". scope of transactionn = 1 sql statement [autocommit=true] hibernate. connection. autoCommit=true makes each statement Commited once its finished, so we cannot commit/rollback 2 or more statements as a part of single unit of work.
No, there is no autocommit in JPA, it doesn't make much sense either, since every change to an entity is a change that eventually goes to the database. With an autocommit, every single change to a property would be a transaction. That is a very special requirement, that doesn't qualify as a feature candidate for JPA.
Hibernate needs to check the underlying JDBC Connection auto-commit status, and disable it if the Connection is set to auto-commit.
From section 13.3.4 of the EJB 3.0 specification:
The enterprise bean’s business methods, message listener methods, business method interceptor methods,life cycle call back interceptor methods, or timeout callback method must not use any resource-manager specific transaction management methods that would interfere with the container’s demarcation of transaction boundaries. For example, the enterprise bean methods must not use the following methods of the java.sql.Connection interface:commit, setAutoCommit, and rollback; or the following methods of the javax.jms.Session interface:commit and rollback.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With