Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setRollbackOnly

 
Sonika Saraswati
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am noticing one problem after calling setRollbackOnly method. here is the scenario.
=================================
SomeBean bean1;
initialize etc..
...

_ctx.setRollbackOnly();//_ctx is entity Context in this example.
throw new MyException("Exception info..."+bean1.getMethod1());
===================================

The throws clause is failing to execute bean1.getMethod1() after the roll back method. Where as if I move bean1.getMethod1() to above roll back method and pass the result of bean1.getMethod1() as a variable (someData) in throws clause, it works. Below is the working code.
=====================================
SomeBean bean1;
initialize etc..
...

String someData = bean1.getMethod1();
_ctx.setRollbackOnly();
throw new MyException("Exception info..."+someData);
=========================================

Any idea why this is happening?

Thanks.
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Spiffy! What container?
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess is that getMethod1() is defined with CMT REQUIRED, REQUIRESNEW or MANDATORY, requiring that a valid transactional context be available. Since you've marked the context for rollback only, it cannot continue the transaction. Perhaps REQUIRESNEW is okay since it will suspend the current transaction to start a new one for that method.

This is a guess; I've been lucky to not come across that, and now we've moved to Spring + Hibernate.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic