Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA + Hibernate + autocommit

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?

like image 570
adrian.tarau Avatar asked Aug 04 '09 15:08

adrian.tarau


People also ask

Does JPA auto-commit?

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.

What is hibernate Autocommit?

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.

What is Autocommit in JPA?

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.

Does Hibernate automatically close connection?

Hibernate needs to check the underlying JDBC Connection auto-commit status, and disable it if the Connection is set to auto-commit.


1 Answers

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.

like image 119
Chris Gummer Avatar answered Sep 19 '22 13:09

Chris Gummer