He logrado hacer que este todo en una sola transaccion utilizando el JOTM y JTA., sin embargo, no esta haciendo el commit en la base de datos, aunque en el log me dice que si que lo hace.
Mi código con JOTM:
Código XML:
Ver original<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="baseTransactionProxy" class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource" > -->
<bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" >
<property name="transactionManager">
<ref local="transactionManager"/>
</property>
<property name="target" ref="publicacionesTarget"/>
<property name="transactionAttributes">
<props>
<prop key="update*">
PROPAGATION_REQUIRED,
ISOLATION_DEFAULT,-BDException,-TablonException, readOnly
</prop>
<prop key="set*">
PROPAGATION_REQUIRED,
ISOLATION_DEFAULT,-BDException,-TablonException, readOnly
</prop>
<prop key="insert*">
PROPAGATION_REQUIRED,
ISOLATION_READ_UNCOMMITTED,-BDException,-TablonException
</prop>
<prop key="delete*">
PROPAGATION_REQUIRED,
ISOLATION_DEFAULT,-BDException,-TablonException, readOnly
</prop>
<prop key="select*">
PROPAGATION_REQUIRED,
ISOLATION_READ_UNCOMMITTED,-BDException,-TablonException
</prop>
<!-- <prop key="select*">
PROPAGATION_SUPPORTS,
ISOLATION_READ_UNCOMMITTED, readOnly
</prop> -->
<prop key="get*">
PROPAGATION_SUPPORTS, ISOLATION_DEFAULT, readOnly
</prop>
</props>
</property>
</bean>
<!-- datasource -->
<bean id="dataSource" class="com.ibatis.common.jdbc.SimpleDataSource"
destroy-method="close">
<!-- destroy-method="finalize"> -->
<constructor-arg>
<map>
<entry key="JDBC.Driver">
<value>${jdbc.driverClassName}</value>
</entry>
<entry key="JDBC.ConnectionURL">
<value>${jdbc.url}</value>
</entry>
<entry key="JDBC.Username">
<value>${jdbc.username}</value>
</entry>
<entry key="JDBC.Password">
<value>${jdbc.password}</value>
</entry>
<entry key="JDBC.DefaultAutoCommit">
<value>false</value>
</entry>
</map>
</constructor-arg>
</bean>
Ahora, en mi action, cuando le digo lo de la transacción hago lo siguiente:
Código Java:
Ver originalJtaTransactionManager tm = (JtaTransactionManager) CargadorBeans.localizar("transactionManager");
TransactionStatus transactionStatus =tm.getTransaction(null);
try {
forward = ejecutar(mapping, form, request, response);
tm.commit(transactionStatus);
//tratamiento excepciones
tm.rollback(transactionStatus);
}
y en el log, me dice que hace lo siguiente:
Código LOG:
Ver original2011/08/03 09:31:13,105 DEBUG org.springframework.transaction.support.AbstractPlatformTransactionManager.handleExistingTransaction(438)===> Participating in existing transaction
2011/08/03 09:31:13,105 DEBUG org.springframework.transaction.interceptor.TransactionAspectSupport.prepareTransactionInfo(279)===> Getting transaction for [MiPaquete.clase.metodo]
2011/08/03 09:31:13,105 DEBUG org.springframework.transaction.support.TransactionSynchronizationManager.getResource(140)===> Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@a65760] for key [com.ibatis.common.jdbc.SimpleDataSource@1b64b70] bound to thread [http-8080-1]
2011/08/03 09:31:13,105 DEBUG com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug(27)===> {conn-100020} Connection
...Sentencias SQL...
y despues de eejecutar las sentencias sql, sigue con lo siquiente:
Código LOG:
Ver original2011/08/03 09:31:13,136 DEBUG org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(309)===> Completing transaction for [miPaquete.clase.metodo]
2011/08/03 09:31:13,136 DEBUG org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(822)===> Triggering beforeCommit synchronization
2011/08/03 09:31:13,136 DEBUG org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCompletion(835)===> Triggering beforeCompletion synchronization
2011/08/03 09:31:13,136 DEBUG org.springframework.transaction.support.TransactionSynchronizationManager.unbindResource(193)===> Removed value [org.springframework.jdbc.datasource.ConnectionHolder@a65760] for key [com.ibatis.common.jdbc.SimpleDataSource@1b64b70] from thread [http-8080-1]
2011/08/03 09:31:13,136 DEBUG org.springframework.jdbc.datasource.DataSourceUtils.doReleaseConnection(312)===> Returning JDBC Connection to DataSource
2011/08/03 09:31:13,136 DEBUG com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug(27)===> Returned connection 33020888 to pool.
2011/08/03 09:31:13,136 DEBUG org.objectweb.jotm.TransactionImpl.getStatus(581)===> TransactionImpl.getStatus()
2011/08/03 09:31:13,136 DEBUG org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(649)===> Initiating transaction commit
2011/08/03 09:31:13,136 DEBUG org.objectweb.jotm.Current.commit(464)===> tx=bb14:38:0:012ceab1ed5eb54f6c...980c02:
2011/08/03 09:31:13,136 DEBUG org.objectweb.jotm.TransactionImpl.commit(209)===> TransactionImpl.commit (tx= bb14:38:0:012ceab1ed5eb54f6c...980c02:)
2011/08/03 09:31:13,136 DEBUG org.objectweb.jotm.TransactionImpl.unsetTimer(919)===> unset timer for tx (timer=org.objectweb.jotm.TimerEvent@1c4d594, tx=bb14:38:0:012ceab1ed5eb54f6c...980c02:)
2011/08/03 09:31:13,136 DEBUG org.objectweb.jotm.TimerEvent.unset(123)===> TimerEvent(bb14:38:0:012ceab1ed5eb54f6c...980c02:).unset
2011/08/03 09:31:13,136 DEBUG org.objectweb.jotm.Current.forgetTx(1147)===> xid=bb14:38:0:012ceab1ed5eb54f6c...980c02:
2011/08/03 09:31:13,136 DEBUG org.objectweb.jotm.Current.forgetTx(1156)===> threadTx.set = null
2011/08/03 09:31:13,136 DEBUG org.objectweb.jotm.Current.removeTxXid(1756)===> remove tx from xid (xid=bb14:38:0:012ceab1ed5eb54f6c...980c02:)
2011/08/03 09:31:13,136 DEBUG org.objectweb.jotm.Current.commit(476)===> threadTx.set null
y el id de la transaccion (bb14:38:0:012ceab1ed5eb54f6c...980c02) es el mismo de la primera transacción generada, es decir, es correcta la transacción que se cierra y se supone hace el commit.
¿tengo algo mal? ¿me hace falta incluir algo?