File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes setRollbackOnly Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "setRollbackOnly" Watch "setRollbackOnly" New topic


Sonika Saraswati

Joined: Nov 22, 2004
Posts: 1
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();
throw new MyException("Exception info..."+someData);

Any idea why this is happening?


Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
Spiffy! What container?

David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
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.
I agree. Here's the link:
subject: setRollbackOnly
It's not a secret anymore!