Announcement Announcement Module
Collapse
No announcement yet.
Spring-Hibernate-Atomikos issue with setting isolation level Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring-Hibernate-Atomikos issue with setting isolation level

    Hi,
    I have been able to integrate spring-hibernate & atomikos for XA transactions in Oracle but facing an issue related to isolation levels.
    When I start a transaction with SERIALIZABLE isolation, it is not propogated to the underlying connection probably because atomikos initializes a pool of connections & reuses the connections from the pool.
    However I have overr-riden the SimpleDataSource bean getConnection method to set the current isolation from the TransactionSynchronizationManager, but still the connection does not behave like in SERIALIZABLE isolation.
    I am using Oracle 10.2 driver & OracleXADataSource as the underlying datasource.

    Please find my configuration below. Here UserContextAwareXADataSource is derived from OracleXADataSource.

    <bean id="ciSetXADataSource" class="com.etrade.ee.orm.impl.UserContextAwareXADa taSource">
    <property name="URL" value="${db1.jdbc.url}" />
    <property name="user" value="${db1.jdbc.username}" />
    <property name="password" value="${db1.jdbc.password}" />
    <property name="schemaRegistry" ref="schemaRegistry" />
    <property name="schema" value="CI_SET" />
    </bean>

    - <bean id="crossSetXADataSource" class="com.etrade.ee.orm.impl.UserContextAwareXADa taSource">
    <property name="URL" value="${db2.jdbc.url}" />
    <property name="user" value="${db2.jdbc.username}" />
    <property name="password" value="${db2.jdbc.password}" />
    <property name="schemaRegistry" ref="schemaRegistry" />
    <property name="schema" value="CROSS_SET" />
    </bean>

    - <bean id="ciSetDB" class="com.atomikos.jdbc.SimpleDataSourceBean" init-method="init" destroy-method="close">
    - <property name="uniqueResourceName">
    <value>XADBMS1</value>
    </property>
    - <property name="xaDataSourceClassName">
    <value>com.etrade.ee.orm.impl.UserContextAwareXADa taSource</value>
    </property>
    - <property name="xaDataSourceProperties">
    <value>URL=${db1.jdbc.url};password=${db1.jdbc.pas sword};user=${db1.jdbc.username};schema=CI_SET</value>
    </property>
    - <property name="exclusiveConnectionMode">
    <value>true</value>
    </property>
    </bean>

    - <bean id="crossSetDB" class="com.atomikos.jdbc.SimpleDataSourceBean" init-method="init" destroy-method="close">
    <property name="uniqueResourceName">
    <value>XADBMS2</value>
    </property>
    - <property name="xaDataSourceClassName">
    <value>com.etrade.ee.orm.impl.UserContextAwareXADa taSource</value>
    </property>
    - <property name="xaDataSourceProperties">
    <value>URL=${db2.jdbc.url};password=${db2.jdbc.pas sword};user=${db2.jdbc.username};schema=CROSS_SET</value>
    </property>
    - <property name="exclusiveConnectionMode">
    <value>true</value>
    </property>
    </bean>

    - <!-- Hibernate session factory -->
    - <bean id="crossSetSF" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    - <property name="dataSource">
    <ref local="crossSetDB" />
    </property>
    - <property name="mappingResources">
    - <list>
    <value>hbm/Audit.hbm.xml</value>
    </list>
    </property>
    - <property name="hibernateProperties">
    - <props>
    <prop key="hibernate.dialect">${db1.hibernate.dialect}</prop>
    <prop key="hibernate.show_sql">false</prop>
    <prop key="hibernate.temp.use_jdbc_metadata_defaults">fa lse</prop>
    <prop key="hibernate.transaction.flush_before_completion ">false</prop>
    </props>
    </property>
    </bean>

    - <!-- Hibernate session factory -->

    - <bean id="ciSetSF" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    - <property name="dataSource">
    <ref local="ciSetDB" />
    </property>
    - <property name="entityInterceptor">
    <property name="mappingResources">
    - <list>
    <value>hbm/Company.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    - <props>
    <prop key="hibernate.dialect">${db1.hibernate.dialect}</prop>
    <prop key="hibernate.temp.use_jdbc_metadata_defaults">fa lse</prop>
    <prop key="hibernate.show_sql">false</prop>
    <prop key="hibernate.transaction.flush_before_completion ">false</prop>
    </props>
    </property>
    </bean>

    <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTran sactionManager">
    - <property name="transactionManager">
    <ref bean="atomikosTransactionManager" />
    </property>
    - <property name="userTransaction">
    <ref bean="atomikosUserTransaction" />
    </property>
    <property name="allowCustomIsolationLevels" value="true" />
    </bean>


    Would appreciate any help in this regard

  • #2
    What are the symptoms of the non atomic behavior? Oracle uses a very advanced mechanism for concurrency control (MVCC) and if this isn't understood, it could behave a little bit unexpected.

    Comment


    • #3
      The issue is not with atomicity of transactions. The issue is with the transaction isolation level. I start one transaction with SERIALIZABLE isolation & send the thread to sleep. Meanwhile I start a new trsnasaction in another JVM & make some changes to a table which was already read by the first transaction.
      When the thread running the first transaction wakes up , the changes done by the second are visible. This should not happen as the first transaction was started with a SERIALIZABLE isolation.This is the issue.

      Comment


      • #4
        Oracle serializable isolation is... Special. Have you used it before? Not on other dbs, but on Oracle?

        Comment


        • #5
          Yes, I have used Oracle SERIALIZEABLE isolation in the non XA environment with Spring transaction manager. It works fine. Have also tried it out in SQLPLUS command line using the alter session command.
          I am facing this issue only in an XA environment with atomikos & with ORACLE XA thin driver. With OCI driver the same issue is observed & I am getting HueristicMessage exception when I try to commit the transaction started in SERIALIZABLE isolation level. Any information or tip will be really useful as we are stuck with this issue of providing XA support in our project.

          Comment


          • #6
            Originally posted by vinodgs View Post
            The issue is not with atomicity of transactions. The issue is with the transaction isolation level. I start one transaction with SERIALIZABLE isolation & send the thread to sleep. Meanwhile I start a new trsnasaction in another JVM & make some changes to a table which was already read by the first transaction.
            Ok.. following so far.

            When the thread running the first transaction wakes up , the changes done by the second are visible. This should not happen as the first transaction was started with a SERIALIZABLE isolation.This is the issue.
            That is very strange.

            If it works in a non xa environment, and doesn't work in an XA environment, the XA environment probably is the cause.

            Do you need that XA transaction? Are multiple databases used within the transaction?

            I am getting HueristicMessage exception
            Can you provide more information about the message? Perhaps it is some kind of optimistic locking failure (caused by the Oracle 08177 error for example).

            Comment

            Working...
            X