Getting org.hibernate.ejb.Ejb3Configuration configure WARN: HHH000144: hibernate.connection.autocommit = false breaks the EJB3 specification in EAP
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 6.3.3
- Hibernate 4.x
Issue
- We are using
persistence.xmland having issue withAutocommit - We have the following persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="TEST_PU" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/OracleDS</jta-data-source>
<jar-file>test.jar</jar-file>
<properties>
<property name="hibernate.cache.use_second_level_cache" value="false"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
<property name="hibernate.connection.autocommit" value="false"/>
<property name="hibernate.jdbc.batch_size" value="100"/>
<property name="hibernate.generate_statistics" value="true"/>
</properties>
</persistence-unit>
</persistence>
- Here the key point is the setting in the
peristence.xml, especially the entry<property name="hibernate.connection.autocommit" value="false"/>is here interesting in a JTA-Datasource, which leads to the following log-Entry in theJBoss-server.logfile:
20.10.2015 14:38:45 Thread<113> org.hibernate.ejb.Ejb3Configuration configure
WARN: HHH000144: hibernate.connection.autocommit = false breaks the EJB3 specification
20.10.2015 14:38:45 Thread<112> org.hibernate.ejb.Ejb3Configuration configure
WARN: HHH000144: hibernate.connection.autocommit = false breaks the EJB3 specification
- Our application deployed in Container-EAR in JBOss EAP 6.3.3, Java 8. Hence if we have a Stateless-SessionBean with TX-Attribute @Supports, what does Hibernate do, if we specify autocimmit=false? The Log says: Hibernate does not like this as it is breaking the EJB3 specification. Would it support such an Enterprise Archive-Application?
Resolution
-
User is using hibernate config parameter and use JPA default. As the SLSB supports tx, an existing tx should get propagated. When the Stateless-SessionBean get called without tx, the EntityManager should create an atomic tx which get committed on em.persist. To be safe user should annotate the SLSB as
@TransactionAttribute(TransactionAttributeType.REQUIRED)to always have a container managed tx. -
The warning states very clearly that user's current configuration violates the EJB3-Spec. Even if all seems to work fine for now, this doesn't imply that it will work as expected under all exceptional conditions. As Red Hat can't cover all potential scenarios out-side the specs within the quality ensurance. Therefore user must assume that any EAP patch can break the behavior user is experience for now, especially in case of exceptions.
-
That's why it is strongly recommend to migrate the application towards spec-compliance. The sooner user'll do so, the less effort this will cause in total, as it will:
- Reduce testing effort on technically testing, if this non-compliant construct works under all conditions for every application release and very EAP patch.
- Reduce future migration effort when migrating to higher JEE spec versions, as user can follow migration guidelines.
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.
-
This only occurs in
Hibernate-4. By removing the property from the persistence unit declarations the log message goes away. User need to set to false anyway and It is sure that Hibernate 4 just ignores that property.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
