• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Facing Issue while spring transaction roll back.

 
prashant shelke
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is code snippet where i m facing problem:


In above scenario records inserted by Loop 1 should be rolled back. Which is not working.
Flow of code is like

TestService.java(where transaction boundaries maintained as below) --> DO --> DAOImpl

TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();

[b]Note: I am using spring.jar version 2.0.1
applicationContext.jpg
This applicationContext.xml
[Thumbnail for applicationContext.jpg]
 
Roopali Gaikwad
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I am able to relsove this prblm.Here are steps.
1. Keep your loop of iteration in service not in DO.
2. Remove the AOP property for the service from ApplicationContext.
3. Create a property of txManager bean under the bean of your service .
4. Create definition of Transaction as follows in the method where we want to set the transaction boundary.
Public void insertData()
{
DefaultTransactionDefinition df = new DefaultTransactionDefinition();
df.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
TransactionStatus ts = txManagerBean.getTransaction(df);
boolean transcationCommitted=false;
try
{
Execute code of insert
}catch(Exception e)
{
txManagerBean.rollback(ts);
transcationCommitted=true;
}
if(!transcationCommitted)
txManagerBean.commit(ts);

}
5. This way we can achieve the transaction condition at the method level.

Hope this will help you
 
prashant shelke
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heyy Roopali Thanks a lot, my ISSUE RESOLVED!.
Thanks
 
prashant shelke
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have FIXED Rollback not working issue at database level, by removing "START TRANSACTION;" & "COMMIT;" in one of STORED PROCEDURE which was getting called in transaction.

Roopali, your answer helped me to maintain rollback for BATCH operations & for nested transactions.

Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic