Quantcast
Channel: Spring Community Forums - Data
Viewing all articles
Browse latest Browse all 297

Spring's Transaction manager not committing trancsactions intermittently

$
0
0
I am using spring 3.0.5 + hibernate with declarative transaction management in one of our components and everything seems to be working fine. But intermittently it so happens that one of the transactions are not commiting. The session executes the sql, keeps the lock on the table rows and never issues a commit to release the lock resulting in application deadlock. I am mentioning below the appContext and the transactional code. Any help in this regard would be appreciable.

<?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:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...ring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schem...ing-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<tx:annotation-driven />

<context:spring-configured />
<context:annotation-config />

<bean id="localDevDS" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbcURL" />
<property name="username" value="user" />
<property name="password" value="pass" />
</bean>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean">
<property name="dataSource" ref="localDevDS" />
<property name="persistenceUnitName" value="componentPU"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.Hibernat eJpaVendorAdapter">
<property name="showSql" value="true"/>
<property name="generateDdl" value="false"/>
<property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect"/>

</bean>
</property>
</bean>

<bean class="org.springframework.orm.jpa.support.Persist enceAnnotationBeanPostProcessor"/>

<context:component-scan base-package="com.company.abc">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Reposit ory" />
</context:component-scan>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionM anager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

</beans>


Object doWork(Object1 obj1,final int obj2, final String obj3) throws Exception {
final int i1 = obj1.geti1();
final int i2 = obj1.geti2();
final int i3 = obj1.geti3();

try {
PlatformTransactionManager transactionManager = (PlatformTransactionManager) AppContextFactory.getBean(BeanKeyEnum.TRANSACTION_ MGR);
TransactionDefinition transactionDefinition = new DefaultTransactionAttribute(TransactionDefinition. PROPAGATION_REQUIRED);
return new TransactionTemplate(transactionManager, transactionDefinition).execute(new TransactionCallback() {

@Override
public Object doInTransaction(TransactionStatus status) {
try {
Table1 obj = new Table1();
obj.setObj2(obj2);

Clob objClob = new SerialClob(obj3.toCharArray());
obj.setClob(objClob);

Table1DAO t1dao = (Table1DAO)AppContextFactory.getBean(
EntitiesAppContextFactory.EntitiesBeanKeyEnum.Tabl e1DAO_BEAN_KEY.getValue());
t1dao.save(obj);

Table2DAO t2dao = (Table2DAO)AppContextFactory.getBean(
EntitiesAppContextFactory.EntitiesBeanKeyEnum.Tabl e2DAO_BEAN_KEY.getValue());

t2dao.setBla(i1);
if(i3<1)
t2dao.incrementBla(i2);
return Boolean.TRUE;
} catch (Exception e){
logger.severe("Exception occurred while trying to transact" + e);
}
return Boolean.FALSE;
}
});
} catch (Throwable e) {
logger.severe("Exception occurred while trying to persist" + e);
}
return Boolean.FALSE;
}


Thanks in advance for your help.

Viewing all articles
Browse latest Browse all 297

Trending Articles