brettwooldridge / HikariCP

光 HikariCP・A solid, high-performance, JDBC connection pool at last.
Apache License 2.0
20.01k stars 2.93k forks source link

AutoCommit is false its not commiting transaction. #1013

Open huzefaalid opened 7 years ago

huzefaalid commented 7 years ago

Dear Brett,

i am facing one issue while using hikariCP for oracle DB connection. I am using atomikos for transaction management. Problem if i am keeping autocommit as false transaction is not getting committed although Jta is calling commit operation. Please find my config files for the same. <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.1.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">

   <bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig"
      p:driverClassName="oracle.jdbc.OracleDriver" p:jdbcUrl="jdbc:oracle:thin:@10.50.200.126:1521:orclebs"
  p:username="T2_EBS" p:password="T2_EBS" p:autoCommit="false"/>

 <bean id="appDataSource"
      class="com.zaxxer.hikari.HikariDataSource">
    <constructor-arg ref="hikariConfig"/>
</bean> 
<tx:annotation-driven transaction-manager="transactionManager"/>
<tx:jta-transaction-manager></tx:jta-transaction-manager>
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"
      depends-on="atomikosTransactionManager,atomikosUserTransaction">
    <property name="transactionManager" ref="atomikosTransactionManager"/>
    <property name="userTransaction" ref="atomikosUserTransaction"/> 
</bean>
<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
      init-method="init" destroy-method="close">
    <property name="forceShutdown" value="false"/>
</bean>

<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.J2eeUserTransaction">
    <property name="transactionTimeout" value="30000"/>
</bean>
<bean id="springJtaPlatform" class="com.tapro.taqframework.config.SpringJtaPlatformAdapter">
    <constructor-arg index="0" ref="transactionManager"></constructor-arg>
</bean>

<bean parent="dataSource" id="defaultJDBCDataSource"/>

<bean id="dataSource" primary="true"
      class="com.tapro.taqframework.persistence.datasources.DatasourceRouter"
      lazy-init="true">
    <property name="targetDataSources">
        <map>
            <entry key="RODS" value-ref="appDataSource"/>
            <entry key="RWDS" value-ref="appDataSource"/>
            <entry key="XADS" value-ref="appDataSource"/>
        </map>
    </property>
    <property name="defaultTargetDataSource" ref="appDataSource"/>
</bean>

<!-- Security datasource - Ideally this is not required - Just for segregation
    have put this -->
<bean id="securityDatasource"
      class="com.tapro.taqframework.persistence.datasources.DatasourceRouter"
      lazy-init="true">
    <property name="targetDataSources">
        <map>
            <entry key="RODS" value-ref="appDataSource"/>
            <entry key="RWDS" value-ref="appDataSource"/>
            <entry key="XADS" value-ref="appDataSource"/>
        </map>
    </property>
    <property name="defaultTargetDataSource" ref="appDataSource"/>
</bean>

<bean id="auditDatasource"
      class="com.tapro.taqframework.persistence.datasources.DatasourceRouter"
      lazy-init="true">
    <property name="targetDataSources">
        <map>
            <entry key="RODS" value-ref="appDataSource"/>
            <entry key="RWDS" value-ref="appDataSource"/>
            <entry key="XADS" value-ref="appDataSource"/>
        </map>
    </property>
    <property name="defaultTargetDataSource" ref="appDataSource"/>
</bean>

<bean id="entityManagerFactory"
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
      parent="abstractEntityManagerFactory" lazy-init="true">
    <property name="dataSource" ref="dataSource"/>
    <property name="persistenceUnitName" value="oracle_pu_jta_atomikos"/>
</bean>

<bean id="defaultEntityManagerFactory"
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
      parent="abstractEntityManagerFactory" lazy-init="true">
    <property name="dataSource" ref="dataSource"/>
    <property name="persistenceUnitName" value="oracle_pu_jta_atomikos"/>
</bean>

<util:map id="entityMangerFactoryMap">
    <entry key="audit" value-ref="entityManagerFactory"/>
    <entry key="securityService" value-ref="entityManagerFactory"/>
</util:map>

<!-- <alias name="defaultEntityManagerFactory" alias="entityManagerFactory"/>-->

<util:properties id="jpaProperties">
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.format_sql">true</prop>
    <prop key="hibernate.transaction.coordinator_class" >jta</prop>
     <prop key="hibernate.transaction.jta.platform">com.atomikos.icatch.jta.hibernate4.AtomikosPlatform</prop>
    <!-- <prop key="hibernate.transaction.factory_class"> 
           com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory 
        </prop>  -->

    <!--<prop key="hibernate.transaction.factory_class">org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory</prop>
    <prop key="hibernate.connection.autocommit">false</prop>-->
    <!--<prop key="hibernate.transaction.jta.platform">com.atomikos.icatch.jta.hibernate4.AtomikosPlatform</prop>-->
    <!--<prop key="hibernate.transaction.jta.platform">org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform</prop>
      <prop key="hibernate.hbm2ddl.auto">update</prop>  -->
  <!--   <prop key="hibernate.hbm2ddl.auto">update</prop>    -->        
    <prop key="hibernate.transaction.flush_before_completion">false</prop>
    <prop key="hibernate.transaction.auto_close_session">true</prop>
    <prop key="hibernate.current_session_context_class">jta</prop>
    <prop key="hibernate.connection.release_mode">auto</prop>
    <prop key="hibernate.jdbc.batch_size">50</prop>
    <prop key="hibernate.jdbc.batch_versioned_data">true</prop>
    <prop key="hibernate.order_inserts">true</prop>
    <prop key="hibernate.order_updates">true</prop>
    <prop key="hibernate.cache.use_second_level_cache">false</prop>
    <prop key="hibernate.id.new_generator_mappings">true</prop> 

</util:properties>

brettwooldridge commented 7 years ago

Have you read this?

https://www.atomikos.com/Documentation/KnownProblems#Hibernate_3.3_40and_Higher_41_Not_Committing_40JPA_41

brettwooldridge commented 7 years ago

Also, try googling:

atomikos not committing spring hibernate

And limit results to the past year or two. You’ve got a lot of moving pieces there, and the odds of it being a bug vs configuration is extremely low.

huzefaalid commented 7 years ago

Thanks Brett for prompt response. I am using Hibernate 5 and spring 4.3.11 as a version. i found working with Atomikos XA DataSource but getting issue with HikariCP by putting autocommit as false.

brettwooldridge commented 6 years ago

@vladmihalcea Any ideas here either?

vladmihalcea commented 6 years ago

i am facing one issue while using hikariCP for oracle DB connection. I am using atomikos for transaction management.

HikariCP is a RESOURCE_LOCAL Connection Pool while Atomikos is a JTA Transaction Manager. You can't use a RESOURCE_LOCAL Connection Pool with an XA Transaction. You need a JTA DataSource which allows the JTA Transaction Manager to enlist the XaResource.

For more details, check out Atomikos documentation.