• 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
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

SessionContext . setRollbackOnly() method doubt.

 
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ETS:
Is this statement correct:
All session beans can call SessionContext.setRollbackOnly().

I tested with Stateless and Stateful and i was able to invoke without any issues.
ETS says: Only Enterprise beans with CMT can invoke the above method.

a) Is this statement correct, if yes please elaborate?
b) What are enterprise beans? I thought they were Session beans.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
setRollBackOnly() is available on SessionContext and MessageDrivenContext.


So this method works successfully if the following conditions are met

1. Session Beans or Message Driven Beans should use CMT (Transaction should be managed by container) and also
2. The method should be called in transactional context


It will throw IllegalStateException if
1. called in non transactional context or
2. called by the BMT bean

-------------------------------------
LakshmiNarayana Kodali
SCJP 5(98%), SCWCD(100%), SCBCD in progress
[ December 26, 2008: Message edited by: LakshmiNarayana Kodali ]
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Following is text form core specification. I hope this will clear your doubt.

An enterprise bean with bean-managed transaction demarcation must not use the getRollbackOnly and setRollbackOnly methods of the EJBContext interface. An enterprise bean with bean-managed transaction demarcation has no need to use these methods, because of the following reasons:
�An enterprise bean with bean-managed transaction demarcation can obtain the status of a transaction by using the getStatus method of the javax.transaction.User-Transaction interface.
� An enterprise bean with bean-managed transaction demarcation can rollback a transaction using the rollback method of the javax.transaction.UserTransaction interface.

The container must throw the java.lang.IllegalStateException if an instance of a bean with bean-managed transaction demarcation attempts to invoke the setRollbackOnly or getRollbackOnly method of the javax.ejb.EJBContext interface.



An enterprise bean with container-managed transaction demarcation can use the setRollbackOnly method of its EJBContext object to mark the transaction such that the transaction can never commit. Typically, an enterprise bean marks a transaction for rollback to protect data integrity before throwing an application exception, if the application exception class has not been specified to automatically cause the container to rollback the transaction.

For example, an AccountTransfer bean which debits one account and credits another account could mark a transaction for rollback if it successfully performs the debit operation, but encounters a failure during the credit operation.
 
She'll be back. I'm just gonna wait here. With this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic