Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What happens if UserTransaction.rollback() is invoked after UserTransaction.commit()  RSS feed

 
Joe Joseph
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In a BMT i have the following code:

UserTransaction.begin();
Insert into a table....
UserTransaction.commit();
// Some lines of code...
UserTransaction.rollback();

I know it is pretty dumb to rollback after the commit. Yet i would like to know what would happen in this case. What i observred is that the Insert statement rolled back. Is this as expected? Is there anything in EJB Specs that mentions this.
Apart from this i would like to know, what would happen in the following cases of BMT:
1. If commit is called after the rollback
2. if i terminate the method without a commit & rollback. What would happen of the tnx? Would is be committed or rolledback?
 
Devaka Cooray
Marshal
Posts: 5323
575
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you have the JPA specs? In your code, the rollback statement should throw an java.lang.IllegalStateException. If you are running on a stateful bean you can terminate the method without committing or roll-backing. So, another method would continue the business logic there after.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!