Announcement Announcement Module
Collapse
No announcement yet.
A strange question about spring transaction and jotm Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • A strange question about spring transaction and jotm

    In my application,I use jotm to manage jta trasaction,but there are Exception:

    [ERROR] 2006-02-08 09:36:23 method:com.fudannet.collierysecurity.action.securi ty.AuthAction.doLogin(AuthAction.java:63)
    - org.springframework.orm.hibernate3.HibernateSystem Exception: java.sql.SQLException: StandardXAConnectionHandle:commit:This connection is part of a global transaction; nested exception is org.hibernate.HibernateException: java.sql.SQLException: StandardXAConnectionHandle:commit:This connection is part of a global transaction
    [ERROR] 2006-02-08 09:36:23 method:com.fudannet.collierysecurity.action.securi ty.AuthAction.doLogin(AuthAction.java:73)
    - org.springframework.orm.hibernate3.HibernateSystem Exception: java.sql.SQLException: StandardXAConnectionHandle:commit:This connection is part of a global transaction; nested exception is org.hibernate.HibernateException: java.sql.SQLException: StandardXAConnectionHandle:commit:This connection is part of a global transaction

    Spring version:1.2.6
    hibernate :3.1
    db2:8.2
    my configuration:

    <bean id="jotm" class="org.springframework.transaction.jta.JotmFac toryBean"/>

    <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTran sactionManager">
    <property name="userTransaction"><ref local="jotm"/></property>
    </bean>

    <bean id="innerDataSource" class="org.enhydra.jdbc.standard.StandardXADataSou rce" destroy-method="shutdown">
    <property name="transactionManager"><ref local="jotm"/></property>
    <property name="driverName"><value>com.ibm.db2.jcc.DB2Driver </value></property>
    <property name="url"><value>jdbc:db2://10.0.0.200:50000/test2</value></property>
    </bean>

    <bean id="dataSource" class="org.enhydra.jdbc.pool.StandardXAPoolDataSou rce" destroy-method="shutdown">
    <property name="dataSource"><ref local="innerDataSource"/></property>
    <property name="transactionManager"><ref local="jotm"/></property>
    <property name="maxSize"><value>10</value></property>
    <property name="user"><value>coal</value></property>
    <property name="password"><value>coal</value></property>
    </bean>

    I am baffled!

    Thank you!!

  • #2
    You need to configure the HB session to use your JTA TransactionManager. What is your configuration?

    Comment


    • #3
      costin:
      Thank you

      To my surprise,when query,update,delete data,it is ok,but not save.The Exception is :
      org.springframework.orm.hibernate3.HibernateSystem Exception: java.sql.SQLException: StandardXAConnectionHandle:commit:This connection is part of a global transaction;

      my hibernate config file:

      <!-- Hibernate config-->
      <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
      <property name="dataSource">
      <ref local="dataSource"/>
      </property>
      <property name="mappingDirectoryLocations">
      <list>
      <value>classpath:/com/fudannet/collierysecurity/module/po/background</value>
      <value>classpath:/com/fudannet/collierysecurity/module/po/baseinfo</value>
      </list>
      </property>
      <property name="hibernateProperties">
      <props>
      <prop key="hibernate.dialect">org.hibernate.dialect.DB2D ialect</prop>
      <prop key="hibernate.show_sql">true</prop>
      </props>
      </property>
      </bean>

      <bean id="logService" parent="baseTransactionProxy">
      <property name="target">
      <bean class="com.fudannet.collierysecurity.service.servi ceimpl.sucurity.LogServiceImpl">
      <property name="logDAO"><ref local="logDAOTarget"/></property>
      </bean>
      </property>
      </bean>
      <bean id="logDAOTarget" class="com.fudannet.collierysecurity.module.dao.da oimpl.security.LogDAOImpl" autowire="byType"/>

      Comment


      • #4
        You need to se the JTA TM on your HB sessionFactory. See the javadocs:



        setJtaTransactionManager

        public void setJtaTransactionManager(TransactionManager jtaTransactionManager) Set the JTA TransactionManager to be used for Hibernate's TransactionManagerLookup. If set, this will override corresponding settings in Hibernate properties. Allows to use a Spring-managed JTA TransactionManager for Hibernate's cache synchronization. Note: If this is set, the Hibernate settings should not define a transaction manager lookup to avoid meaningless double configuration.

        See Also:LocalTransactionManagerLookup

        Comment


        • #5
          glad to see your reply!Thanks a lot.

          I have see the docs about:

          setJtaTransactionManager

          public void setJtaTransactionManager(TransactionManager jtaTransactionManager) Set the JTA TransactionManager to be used for Hibernate's TransactionManagerLookup. If set, this will override corresponding settings in Hibernate properties. Allows to use a Spring-managed JTA TransactionManager for Hibernate's cache synchronization. Note: If this is set, the Hibernate settings should not define a transaction manager lookup to avoid meaningless double configuration.

          See Also:LocalTransactionManagerLookup
          but to jotm,I donot know how to set property:jtaTrasactionManager ,I try:

          Code:
          <property name="hibernateProperties"> 
          			<props>
          				<prop key="hibernate.dialect">org.hibernate.dialect.DB2Dialect</prop>
          				<prop key="hibernate.show_sql">true</prop>
          				<prop key="transaction.factory_class">
          					net.sf.hibernate.transaction.JTATransactionFactory
          				</prop>
          				<prop key="transaction.manager_lookup_class">
          					net.sf.hibernate.transaction.JOTMTransactionManagerLookup
          				</prop>
          				<prop key="jta.UserTransaction">java:comp/env/UserTransaction</prop>
          			</props>
          		</property>
          my tomcat config file:

          Code:
          <Resource name="UserTransaction" auth="Container" type="javax.transaction.UserTransaction"/>
          			<ResourceParams name="UserTransaction">
          			<parameter>
          				<name>factory</name>
          				<value>org.objectweb.jotm.UserTransactionFactory</value>
          			</parameter>
          			<parameter>
          				<name>jotm.timeout</name>
          				<value>60</value>
          			</parameter>
          		</ResourceParams>
          but there is the same wrong,Why?

          Comment


          • #6
            I try it like:
            Code:
            <bean id="jotmTransactionManager" class="org.springframework.jndi.JndiObjectFactoryBean">
                    <property name="proxyInterface" value="javax.transaction.TransactionManager"/>
                    <property name="jndiName" value="java:comp/UserTransaction"/>
                </bean>
            	<!-- Hibernate config-->
            	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            		<property name="dataSource">
            			<ref local="dataSource"/>
            		</property>
            		<property name="jtaTransactionManager">
            			<ref local="jotmTransactionManager"/>
            		</property>
            		<property name="mappingDirectoryLocations">
            			<list>
            				<value>classpath:/com/fudannet/collierysecurity/module/po/background</value>
            				<value>classpath:/com/fudannet/collierysecurity/module/po/baseinfo</value>
            			</list>
            		</property>
            		<property name="hibernateProperties"> 
            			<props>
            				<prop key="hibernate.dialect">org.hibernate.dialect.DB2Dialect</prop>
            				<prop key="hibernate.show_sql">true</prop>
            			</props>
            		</property>	
            	</bean>
            the same wrong appear! I'm crazy!!!

            Comment


            • #7
              You need to pass to HB sessionfactory Spring JTA transaction manager - the userTransaction that you retrieve from JNDI should be used to create the JTATM and then this, passed on to HB SF. This is documented in detail in Spring javadocs:
              <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTran sactionManager">
              <property name="userTransaction" ref="jotmTransactionManager"/>
              </bean>
              Btw, note that you can create the JOTM TM through Spring completely by using JotmFactoryBean.

              Comment


              • #8
                Yes,two ways:
                1:JotmFactoryBean

                my config file:

                Code:
                <bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean"/>
                	
                	<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
                		<property name="userTransaction"><ref local="jotm"/></property>
                	</bean>
                	
                	<bean id="innerDataSource" class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown">
                		<property name="transactionManager"><ref local="jotm"/></property>
                		<property name="driverName"><value>com.ibm.db2.jcc.DB2Driver</value></property>
                		<property name="url"><value>jdbc:db2://10.0.0.200:50000/test2</value></property>
                	</bean>
                 
                	<bean id="dataSource" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method="shutdown">
                		<property name="dataSource"><ref local="innerDataSource"/></property>
                		<property name="transactionManager"><ref local="jotm"/></property>
                		<property name="maxSize"><value>10</value></property>
                		<property name="user"><value>coal</value></property>
                 		<property name="password"><value>coal</value></property>
                	</bean>
                	<bean id="jotmTransactionManager" class="org.springframework.jndi.JndiObjectFactoryBean">
                        <property name="proxyInterface" value="javax.transaction.TransactionManager"/>
                        <property name="jndiName" value="java:comp/UserTransaction"/>
                    </bean>
                
                	<!-- Hibernate config-->
                	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
                		<property name="dataSource">
                			<ref local="dataSource"/>
                		</property>
                
                		<property name="jtaTransactionManager">
                			<ref local="jotm"/>
                		</property>
                
                		<property name="mappingDirectoryLocations">
                			<list>
                				<value>classpath:/com/fudannet/collierysecurity/module/po/background</value>
                				<value>classpath:/com/fudannet/collierysecurity/module/po/baseinfo</value>
                			</list>
                		</property>
                		<property name="hibernateProperties"> 
                			<props>
                				<prop key="hibernate.dialect">org.hibernate.dialect.DB2Dialect</prop>
                				<prop key="hibernate.show_sql">true</prop>
                			</props>
                		</property>	
                	</bean>
                
                	<bean id="baseTransactionProxy" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> 
                        <property name="transactionManager"><ref bean="transactionManager"/></property> 
                        <property name="transactionAttributes"> 
                            <props> 
                				<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>	
                				<prop key="save*">PROPAGATION_REQUIRED</prop>
                				<prop key="update*">PROPAGATION_REQUIRED</prop>
                				<prop key="delete*">PROPAGATION_REQUIRED</prop>
                            </props> 
                        </property> 
                        <property name="proxyTargetClass"> 
                			<value>true</value> 
                		</property> 
                    </bean>
                2:
                <bean id="jotmTransactionManager" class="org.springframework.jndi.JndiObjectFactoryB ean">
                <property name="proxyInterface" value="javax.transaction.TransactionManager"/>
                <property name="jndiName" value="java:comp/UserTransaction"/>
                </bean>

                <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTran sactionManager">
                <property name="userTransaction"><ref local="jotmTransactionManager"/></property>
                </bean>

                the other is same,

                but it seem the same wrong!

                Comment


                • #9
                  Inside your app-context it seems you are using both of them - retrieval from JNDI and spring declaration - you should use only one. If the problem still persists then I suggest you take this issue with the devs mailing list. Make sure you try the latest hibernate and jotm libraries and search their forum also.

                  Comment


                  • #10
                    Costin:

                    I'm sure I only use a way of them

                    jotm's version is 2.0.10 ,it is the latest.

                    hibernate version is 3.1
                    spring 1.2.6

                    I test once just now,find it seem to use jdbcTransaction,the Exception message :

                    Code:
                    Hibernate: delete from USERBS where PRIKEY in (167)
                    [ERROR] 2006-02-10 16:47:17 method:org.hibernate.transaction.JDBCTransaction.toggleAutoCommit(JDBCTransaction.java:178)
                     - Could not toggle autocommit
                    java.sql.SQLException: StandardXAConnectionHandle:setAutoCommit This connection is part of a global transaction
                    	at org.enhydra.jdbc.standard.StandardXAConnectionHandle.setAutoCommit(StandardXAConnectionHandle.java:122)
                    	at org.hibernate.transaction.JDBCTransaction.toggleAutoCommit(JDBCTransaction.java:174)
                    ......
                    can it be the cause of Spring? or version(hibernate?jotm?)

                    Comment


                    • #11
                      Just to make sure you can use hibernate 3.1.2 which is, AFAIK the latest.
                      Your problem is clearly that HB uses the JDBC TM instead of JTA - in your case Jotm.
                      I suggest you review your configuration, start from scratch if you need and turn on logging to make sure that the system reacts to your changes. Usually a classpath problem or lost file that is not being updated cause all this grief.

                      Comment


                      • #12
                        same error, google brings me here.
                        For all the followers, here is the answer (works for me at least):

                        If you use DB2, create a DB2XADataSource bean as your inner dataSource .
                        If you use MSSQL, create a SQLServerXADataSource bean as your inner dataSource.
                        ....

                        Enjoy goolging!

                        Comment

                        Working...
                        X