Hibernation error: Failed to enable auto-commit in active global transaction

I get an error while deploying our application.

Environment:

  • Jboss 7.1.3 + Hibernate 4 + JPA
  • OJDBC: ojdbc6.jar

The stacktrace element is as follows:

09:13:30,703 WARN [org.hibernate.engine.jdbc.internal.JdbcServicesImpl] (ServerService Thread Pool -- 127) HHH000341: Could not obtain connection metadata : could not turn on auto-commit in an active global transaction 09:13:30,703 INFO [org.hibernate.engine.jdbc.internal.LobCreatorBuilder] (ServerService Thread Pool -- 127) HHH000422: Disabling contextual LOB creation as connection was null 09:13:30,704 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 127) MSC00001: Failed to start service jboss.persistenceunit."css-ear-0.5.3-SIT.ear/css-submission-0.5.3-SIT.war#css-submission-PU": org.jboss.msc.service.StartException in service jboss.persistenceunit."css-ear-0.5.3-SIT.ear/css-submission-0.5.3-SIT.war#css-submission-PU": java.lang.NullPointerException at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:100) [jboss-as-jpa-7.1.3.Final.jar:7.1.3.Final] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_21] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_21] at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_21] at org.jboss.threads.JBossThread.run(JBossThread.java:122) [jboss-threads-2.0.0.GA.jar:2.0.0.GA] Caused by: java.lang.NullPointerException at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:207) at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131) at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:73) at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2279) at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2275) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1744) at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:94) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:905) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890) at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74) at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:197) [jboss-as-jpa-7.1.3.Final.jar:7.1.3.Final] at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.access$500(PersistenceUnitServiceImpl.java:57) [jboss-as-jpa-7.1.3.Final.jar:7.1.3.Final] at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:96) [jboss-as-jpa-7.1.3.Final.jar:7.1.3.Final 

Data source configuration in standalone.xml file,

 <xa-datasource jta="true" jndi-name="java:jboss/datasources/PsaDS" pool-name="PsaDS" enabled="true" use-java-context="true" use-ccm="true"> <xa-datasource-property name="URL"> jdbc:oracle:thin:@<hsot> </xa-datasource-property> <driver>oracle</driver> <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation> <xa-pool> <min-pool-size>2</min-pool-size> <max-pool-size>50</max-pool-size> <prefill>true</prefill> </xa-pool> <security> <user-name>user</user-name> <password>pwd</password> </security> 

The driver we use is

 <drivers> <driver name="oracle" module="com.oracle.ojdbc6"> <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class> </driver></drivers> 
+6
source share
2 answers

Try the following changes to your standalone.xml in the <xa-datasource> definition tags:

Add the following to the <xa-pool> :

 <is-same-rm-override>false</is-same-rm-override> <no-tx-separate-pools>true</no-tx-separate-pools> 

According to the documentation:

no-tx-separate-pools: the presence of this element indicates that two connection pools are used to isolate the connections used with the JTA transaction, which are used without the JTA transaction. Pools are lazily built upon first use. Its use case is for implementing XA (and possibly other providers) XA that do not like the use of XA connection with and without JTA transaction.

If this does not work alone, try adding this to the <xa-datasource> :

 <validation> <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleValidConnectionChecker"/> <stale-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleStaleConnectionChecker"/> <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleExceptionSorter"/> </validation> 
+1
source

I have never worked with JBoss + Hibernate. Therefore, I do not try this setting. Read only the documentation. Please try separetly these settings:

A) Sleep mode properties

You must configure hibernate.properties . I found this additional property in the documentation:

hibernate.connection.autocommit

Enables auto-update for JDBC federated connections (this is not recommended).

eg. true | Lying

documentation link

B) standalone.xml

<share-prepared-statements> - The goal is to circumvent dubious driver behavior when the driver applies automatic semantics commit to local transactions. with the cache enabled, instructions should two requests in the same transaction return the same (from jboss-4.0.2 - false by default).

 Connection c = dataSource.getConnection(); // auto-commit == false PreparedStatement ps1 = c.prepareStatement(...); ResultSet rs1 = ps1.executeQuery(); PreparedStatement ps2 = c.prepareStatement(...); ResultSet rs2 = ps2.executeQuery(); 

Assuming prepared statements are the same. For some drivers, ps2.executeQuery () automatically closes rs1, so we really need two real prepared statements behind the scenes. This should be for semantics of automatic commit, where re-executing the request starts a new transaction automatically. For drivers that follow the specification, you can set it to true to use the same real prepared statement.

documentation link

+1
source

Source: https://habr.com/ru/post/955745/


All Articles