복붙노트

[SPRING] 트랜잭션 롤백이지만 레코드가 삽입됩니다.

SPRING

트랜잭션 롤백이지만 레코드가 삽입됩니다.

안녕 모두 내가 응용 프로그램 구성을 jsf, 봄 3.0, hybernate + JPA 및 XA 변환 관리 및 mysql에 대한 atomikos를 사용하여 내 백엔드, 여기에 모든 일은 잘 작동하지만, 예외가 롤백해야 던지기를 던지고있다 일어나지 않습니다 !! 여기에 우리의 응용 프로그램에 대한 작은 흐름입니다        내 서비스 클래스에서 jsfmanagedbean을 사용하여 내 서비스를 시작합니다. 내 변환이 시작됩니다.

TextileUIBean.java          package com.textile.web;          공용 클래스 TextileUIBean extends BaseManagedBean은 Serializable을 구현하고,          {          public insertPaymentDetails ()             {            PaymentDetails PaymentDetails = 새로운 PaymentDetails ();           // 값은 하드 코딩되어 있습니다. 단 2 개의 propereties는            PaymentDetails.setCustomerName ( "Manikandan");            PaymentDetails.setAmount (1000);            getTextileManager (). insertPaymentDetails (PaymentDetails);            }               공용 ITextileManager getTextileManager () {              textileManager = (ITextileManager) getBean ( "textileManager");              return textileManager;             }            }

   service class


  package com.textile.web
       public interface ITextileManager 
       {
         public void insertPaymentDetails(PaymentDetails PaymentDetails);
       }
        package com.textile.web
        public class TextileManager implements ITextileManager 
            {
            ITextileBusiness  TextileBusiness ;

            public void setTextileBusiness(ITextileBusiness textileBusiness) {
           this.textileBusiness = textileBusiness;
             }
             void insertPaymentDetails(PaymentDetails PaymentDetails)
             {
              TextileBusiness.insertPaymentDetails(PaymentDetails);


             }

        and my business class is 


package com.textile.web

             public interface ITextileBusiness
             {
              public void insertPaymentDetails(PaymentDetails PaymentDetails);
             }

             package com.textile.web
             public class TextileBusiness implements ITextileBusiness 
             {
             ITextileDao  textileDao;

            public void setTextileDao(ITextileDao textileDao) {
           this.textileDao = textileDao;
             }
             void insertPaymentDetails(PaymentDetails ormPaymentTable)
             {

               OrmPaymentTable ormPaymentTable= OrmPaymentTable();
                ormPaymentTable.setCustomerName(PaymentDetails.getCustomerName());
           ormPaymentTable.setAmount(PaymentDetails.getAmount(););
              textileDao.insertPaymentDetails(ormPaymentTable);
                               int a=0;
                if(a==0)
                    throw new BusinessException("Transcation Rollback");            

             }
             }
         and my dao class is 


 package com.textile.web
             public interface IPaymentsDao {
              public void insertPaymentDetails(OrmPaymentTable ormPaymentTable);
              }
               package com.textile.web
               public class PaymentsDao implements IPaymentsDao
               {
               void insertPaymentDetails(OrmPaymentTable ormPaymentTable)
               {
               this.getJpaTemplate().persist(ormPaymentTable);
                  after this line the record is insertinf into table               
               }               
               }


           my FacesConfig.xml is 


   <application>
            <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
            <locale-config>
            <default-locale>en</default-locale>
            <supported-locale>en</supported-locale>
            </locale-config>
            <message-bundle>Messages</message-bundle>
            </application>
            <managed-bean>          <managed-bean-name>textileUIBean</managed-bean-name>                                                    <managed-bean-class>com.textile.web.TextileUIBean</managed-bean-class>
    <managed-bean-scope>view</managed-bean-scope>
</managed-bean>

내 applicationConfig.xml 파일은

<beans:bean id="dataSource"
        class="org.springframework.jndi.JndiObjectFactoryBean" >
        <beans: property name="jndiName">
            <beans: value>java:comp/env/jdbc/textWeb</beans:value>
        </beans: property> 
        <beans: property name="resourceRef">
            <beans:value>true</beans:value>
        </beans: property>
     </beans: bean>
        <beans: bean id="jpaTemplate" class="org.springframework.orm.jpa.JpaTemplate">
        <beans: property name="entityManagerFactory">
            <beans: ref bean="entityManagerFactory" />
        </beans: property>
    </beans: bean>
    <beans: bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <!-- hidden by shiju  because we need one datasource support its  in prsistence.xml !-->
        <beans: property name="dataSource">
            <beans: ref bean="dataSource" />
        </beans: property>
         <beans: property name="persistenceUnitName" value="payhub" />
        <beans: property name="jpaVendorAdapter">
            <beans:bean
                class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <beans: property name="generateDdl" value="false" />
                <beans: property name="showSql" value="true" />
                <beans: property name="databasePlatform" value="${database.target}" />
            </beans: bean>
        </beans: property>
        <beans: property name="persistenceXmlLocation">
            <beans: value>classpath:META-INF/persistence.xml</beans:value>
        </beans: property>
    </beans: bean>
<beans:bean id="textileManager"
        class=" com.textile.web.TextileManager">
        <beans: property name="textileBusiness" ref="textileBusiness" />
    </beans: bean>
    <beans: bean id="textileBusiness" class="com.textile.web.TextileBusiness">
        <beans: property name="textileDao" ref="textileDao" />       
    </beans: bean>
    <beans: bean id="textileDao" class="com.textile.web.textileDao">
        <beans: property name="jpaTemplate">
            <beans: ref bean="jpaTemplate"/>
        </beans: property>
    </beans: bean>

     <aop:config>
            <aop:pointcut id="fooServiceOperation"  expression="execution(* com.textile.web.*.*(..))"/>
             <aop:advisor advice-ref="txAdvice" pointcut-ref="fooServiceOperation"/>
             </aop:config>
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
     <tx:attributes>             
           <tx:method name="*" propagation="REQUIRED"/>
        </tx:attributes>
    </tx:advice>

        <beans: bean id="atomikosTransactionManager"
        class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init"
        destroy-method="close">
        <beans: property name="forceShutdown" value="true" />
        <beans: property name="startupTransactionService" value="true" />
    </beans:bean>

    <beans:bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
        <beans: property name="transactionTimeout">
            <beans: value>3000</beans:value>
        </beans: property>
    </beans:bean>

    <beans: bean id="transactionManager"
        class="org.springframework.transaction.jta.JtaTransactionManager">
        <beans: property name="transactionManager">
            <beans: ref bean="atomikosTransactionManager" />
        </beans: property>
        <beans: property name="userTransaction">
            <beans: ref bean="atomikosUserTransaction"/>
        </beans: property>
            <beans: property name="rollbackOnCommitFailure" value="true">
            </beans: property>
    </beans: bean>

 and orm.xml file is 




<entity class="OrmPaymentTable" name="OrmPaymentTable">
<table name="ta_payment" />
<attributes>
<id name="paymentId">
<column name="USER_ID" />
<generated-value strategy="AUTO" />
</id>
<basic name="customerName">
<column name="CUST_NAME" length="50" />
</basic>
<basic name="amount">
<column name="AMOUNT" length="50" />
</basic>
</attributes>
</entity> 

<persistence-unit name="payhub" transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider> 
        <jta-data-source>java:comp/env/jdbc/textWeb</jta-data-source>
         <mapping-file>META-INF/orm.xml</mapping-file>
         <class>com.textile.web.OrmPaymentTable</class>
         <properties>
            <property name="hibernate.transaction.manager_lookup_class"
                value="com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup"/>

             <property name="hibernate.transaction.factory_class"
                value="org.hibernate.transaction.JTATransactionFactory" />
 </properties>
    </persistence-unit>
</persistence>

그리고 나는 jndi를 meta-inf / context.xml에 설정했다.

<Context>
         <Transaction factory="com.atomikos.icatch.jta.UserTransactionFactory"/> 
         <Resource name="jdbc/textWeb" auth="Container"
        driverClassName="com.mysql.jdbc.Driver" user="root" password="root"
        type="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" factory="com.mysql.jdbc.jdbc2.optional.MysqlDataSourceFactory"
        url="jdbc:mysql://localhost:3306/textWeb" explicitUrl="true"
        pinGlobalTxToPhysicalConnection="true">
    </Resource> 
    </Context>

web.xml 

         <resource-ref>
   <description>PaymentsDatabase</description>
   <res-ref-name>jdbc/textWeb</res-ref-name>
   <res-type>javax.sql.DataSource</res-type>
   <res-auth>Container</res-auth>
   <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

로그를 추적합니다. 내 트랜잭션 로그 세부 정보를 봅니다.

 78 [main] INFO atomikos - USING core version: 3.6.4
78 [main] INFO atomikos - USING com.atomikos.icatch.console_file_name = tm.out
78 [main] INFO atomikos - USING com.atomikos.icatch.console_file_count = 1
78 [main] INFO atomikos - USING com.atomikos.icatch.automatic_resource_registration = true
78 [main] INFO atomikos - USING com.atomikos.icatch.client_demarcation = false
78 [main] INFO atomikos - USING com.atomikos.icatch.threaded_2pc = true
78 [main] INFO atomikos - USING com.atomikos.icatch.serial_jta_transactions = false
78 [main] INFO atomikos - USING com.atomikos.icatch.log_base_dir = .\
94 [main] INFO atomikos - USING com.atomikos.icatch.console_log_level = WARN
94 [main] INFO atomikos - USING com.atomikos.icatch.max_actives = 50
94 [main] INFO atomikos - USING com.atomikos.icatch.checkpoint_interval = 500
94 [main] INFO atomikos - USING com.atomikos.icatch.enable_logging = false
94 [main] INFO atomikos - USING com.atomikos.icatch.output_dir = .\
94 [main] INFO atomikos - USING com.atomikos.icatch.log_base_name = tmlog
94 [main] INFO atomikos - USING com.atomikos.icatch.console_file_limit = 0
94 [main] INFO atomikos - USING com.atomikos.icatch.max_timeout = 300000
94 [main] INFO atomikos - USING com.atomikos.icatch.tm_unique_name = PaymentsTransactions
94 [main] INFO atomikos - USING java.naming.factory.initial = com.sun.jndi.rmi.registry.RegistryContextFactory
94 [main] INFO atomikos - USING java.naming.provider.url = rmi://localhost:1099
94 [main] INFO atomikos - USING com.atomikos.icatch.service = com.atomikos.icatch.standalone.UserTransactionServiceFactory
94 [main] INFO atomikos - USING com.atomikos.icatch.force_shutdown_on_vm_exit = false
94 [main] INFO atomikos - USING com.atomikos.icatch.default_jta_timeout = 10000
INFO - JtaTransactionManager.checkUserTransactionAndTransactionManager(469) | Using JTA UserTransaction: com.atomikos.icatch.jta.UserTransactionImp@16a6027
INFO - JtaTransactionManager.checkUserTransactionAndTransactionManager(480) | Using JTA TransactionManager: com.atomikos.icatch.jta.UserTransactionManager@e68513
DEBUG - NameMatchTransactionAttributeSource.addTransactionalMethod(94) | Adding transactional method [*] with attribute [PROPAGATION_REQUIRED,ISOLATION_DEFAULT]
DEBUG - AbstractPlatformTransactionManager.getTransaction(365) | Creating new transaction with name [com.evolvus.payments.manager.IPaymentsManager.findColumnChartDisplayByGateWays]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
40500 [http-8080-Processor24] WARN atomikos - Attempt to create a transaction with a timeout that exceeds com.atomikos.icatch.max_timeout - truncating to: 300000
40641 [http-8080-Processor24] INFO atomikos - THREADS: using JDK thread pooling...
40703 [http-8080-Processor24] INFO atomikos - createCompositeTransaction ( 3000000 ): created new ROOT transaction with id PaymentsTransactions0000100688
DEBUG - AbstractPlatformTransactionManager.handleExistingTransaction(470) | Participating in existing transaction
DEBUG - AbstractPlatformTransactionManager.handleExistingTransaction(470) | Participating in existing transaction
DEBUG - AbstractPlatformTransactionManager.processRollback(850) | Participating transaction failed - marking existing transaction as rollback-only
DEBUG - JtaTransactionManager.doSetRollbackOnly(1060) | Setting JTA transaction rollback-only
49110 [http-8080-Processor24] INFO atomikos - setRollbackOnly() called for transaction PaymentsTransactions0000100688
DEBUG - AbstractPlatformTransactionManager.processRollback(843) | Initiating transaction rollback
49172 [http-8080-Processor24] INFO atomikos - afterCompletion ( STATUS_ROLLEDBACK ) called  on Synchronization: org.hibernate.transaction.CacheSynchronization
49172 [http-8080-Processor24] INFO atomikos - afterCompletion ( STATUS_ROLLEDBACK ) called  on Synchronization: org.hibernate.ejb.EntityManagerImpl$1@1f6e48a
49172 [http-8080-Processor24] INFO atomikos - rollback() done of transaction PaymentsTransactions0000100688

당신이 나를 도울 수 ?

해결법

  1. ==============================

    1.분명히 데이터베이스 삽입은 트랜잭션 관리자의 현재 트랜잭션 범위 내에서 일어나지 않습니다.

    분명히 데이터베이스 삽입은 트랜잭션 관리자의 현재 트랜잭션 범위 내에서 일어나지 않습니다.

    몇 가지 아이디어 :

    1) 귀하의 게시글에없는 것일 수도 있지만 서비스 클래스에 Spring @ Transactional 주석이 표시되지 않습니다. 트랜잭션 경계를 제어하기위한 전략은 무엇입니까?

    2) JNDI를 사용하기 때문에 데이터 소스를 볼 수 없지만 Atomikos를 사용하는 경우 XA 인식 풀링 데이터 소스를 사용해야합니다. 너?

    3) 처리중인 SQL 명령을 정확하게 보려면 Atomikos 정상 로깅을 DEBUG로 늘려야합니다.

    4) Atomikos는 일반 로그 파일 외부에있는 트랜잭션 로그를 유지합니다. 이들은 복구 및 기타 목적으로 사용됩니다. 또한 단서를 확인해야합니다.

    희망이 도움이됩니다.

    최신 정보:

    MySQL은 XA 트랜잭션에 몇 가지 한계가있다. context.xml에서이 구성을 시도해보고 적어도 작동하는지 확인하십시오. Atomikos의 XA 인식 (XA 가능) 데이터 소스를 사용합니다. 이것이 작동하면 거기에서 갈 수 있습니다.

    엔티티 관리자에 삽입 할 JNDI 데이터 소스를 정의하십시오.

  2. from https://stackoverflow.com/questions/4447777/transaction-rollbacks-but-a-record-is-inserted by cc-by-sa and MIT license