• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

BMT bean setRollbackOnly

 
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What would happen if a BMT bean called setRollbackOnly on the userTransaction object and then later attempts to call commit on the user transaction object? I assume it would cause an error. Which one?
Thanks
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Keith,
I haven't read anywhere in the spec, as to what would happen if a BMT obtains the UserTransaction intreface and calls the setRollbackOnly().
A CMT bean is supposed to call setRollbackOnly () or getRollbackOnly() on the SessionContext. If a BMT calls setRollbackOnly() or getRollbackOnly(), the Container is supposed to throw the IllegalStateException
Also if a CMT calls setRollbackOnly () or getRollbackOnly() on the Session Context and the Tx attribute is Not Supported, Never or Supports, the Container is supposed to throw the IllegalStateException
I would infer that if a BMT invokes the UserTransaction.setRollbackOnly(), the COntainer would deem the request as illegal and throw the IllegalStateException.
Any comments on that ?
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
keith i was wondering about this as well. If a Bean Provider can simply ignore the value of a UserTransacton.getStatus() call and call UserTransaction.commit() even is the transaction had been marked for rollback.
Since i couldn't find an answer in the spec or on the boards I wrote a simple session bean that did just that -- and it ran just fine.
It seems that UserTransaction.setRollbackOnly() will not enforce the rollback - the developer needs to check the satus of the UserTransaction and then decide to rollback() or commit().
Granted my experience with EJBs extends to the Reference Implementation container. If you see anything wrong with this please post a reply.
The session bean's biz method was as follows:
public void testBiz(){
UserTransaction ut = ctx.getUserTransaction();

try {
ut.begin();

ut.setRollbackOnly();

System.out.println(String.valueOf(ut.getStatus()));

ut.commit();
} catch (Exception e) { //the methods in the try block throw more than 6 distinct exceptions - i used a broad catch(Exception e) just to see if any exceptions were called and throw a system exception
throw new EJBException(e);
}

}
 
carlos fernandez
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Keith I take everything back that i said.
If you try that -- the method will throw a RolledbackException.
Why didn't this happen when i posted earlier today . . . i sort of forgot to call the business method in question from my client
Carlos
 
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got javax.transaction.RollbackException
if i call commit() on tx has setRollbackOnly.
why not javax.transaction.TransactionRolledbackException or
javax.ejb.TransactionRolledbackLocalException

???
[ March 31, 2004: Message edited by: Weerawit Maneepongsawat ]
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to HF EJB, the javax.ejb.TransactionRolledBackException is NOT thrown if the failure to commit is because of an explicit previous call to setRollBackOnly (which is, in this case). So maybe that explains y TransactionRolledBackException is not thrown. But i wud like to know more abt javax.transaction.RollBackException....bcos its not mentioned in HF EJB. has it figured in the SCBCD exam ? any other scenarios in which its thrown?
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From Sun site
RollbackException - Thrown to indicate that the transaction has been rolled back rather than committed.
Methods in javax.transaction that throw RollbackException
void UserTransaction.commit()
Complete the transaction associated with the current thread.
void Transaction.commit()
Complete the transaction represented by this Transaction object.
boolean Transaction.enlistResource(XAResource xaRes)
Enlist the resource specified with the transaction associated with the target Transaction object.
void Transaction.registerSynchronization(Synchronization sync)
Register a synchronization object for the transaction currently associated with the target object.
void TransactionManager.commit()
Complete the transaction associated with the current thread.
reply
    Bookmark Topic Watch Topic
  • New Topic