aspose file tools*
The moose likes Other Application Frameworks and the fly likes Facing Issue while spring transaction roll back. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Facing Issue while spring transaction roll back." Watch "Facing Issue while spring transaction roll back." New topic
Author

Facing Issue while spring transaction roll back.

prashant shelke
Greenhorn

Joined: Mar 10, 2009
Posts: 14
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



[Thumbnail for applicationContext.jpg]

Roopali Gaikwad
Greenhorn

Joined: Mar 05, 2009
Posts: 4
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

Joined: Mar 10, 2009
Posts: 14
Heyy Roopali Thanks a lot, my ISSUE RESOLVED!.
Thanks
prashant shelke
Greenhorn

Joined: Mar 10, 2009
Posts: 14
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!
 
 
subject: Facing Issue while spring transaction roll back.