This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Facing Issue while spring transaction roll back.  RSS feed

 
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
[Thumbnail for applicationContext.jpg]
This applicationContext.xml
 
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!
 
I wish to win the lottery. I wish for a lovely piece of pie. And I wish for a tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!