aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Transactions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Transactions" Watch "Transactions" New topic
Author

Transactions

Emad El-Agouz
Greenhorn

Joined: Feb 21, 2005
Posts: 21
Hello All,
I have two questions regarding transactions:

1. When inplementing SessionSynchronization for Sesion Beans, the callback method "beforeCompletion()" is said to run before the end of the transaction -after the business method end- OK.
It is said that in that method you can update the database before end of transaction, but how could I know whether the transaction will commit or rollbact while this methods runs before the end of transaction?
In other words, if I updated the DB and then the transaction rollback then how could I return the old value of the db?

2.I do not understand why Message Driven Beans can use only 2 attributes only (Required or NotSupported)?
more clarification needed for why the other attributes are not needed.

Thank you in advance


Emad El-Agouz<br />Software Engineer<br />-----------------<br />SCJP,SCWCD,SCBCD & SCEA (Pt 1)<br />IBM 399
Sanju Thomas
Ranch Hand

Joined: Dec 29, 2004
Posts: 243
Originally posted by Emad Al-Agouz:


1. When inplementing SessionSynchronization for Sesion Beans, the callback method "beforeCompletion()" is said to run before the end of the transaction -after the business method end- OK.

2.I do not understand why Message Driven Beans can use only 2 attributes only (Required or NotSupported)?



1. Yea, beforeCompletion () will be invoked by the container before the completion of the transaction. That means before either transaction rollback or transaction commit.

I think that, in this method you can do all finalization operation depends up on the status of the transaction. You can get the status of the transaction from userTransaction.getStatus() in BMT and You can use EJBContext.getRollbackOnly() in the case of CMT.


2. MDB have no client view, so rest of the transaction attributes are not meaningful.
Leena Diwan
Ranch Hand

Joined: Jun 18, 2001
Posts: 351
Originally posted by Emad Al-Agouz:
2.I do not understand why Message Driven Beans can use only 2 attributes only (Required or NotSupported)?
more clarification needed for why the other attributes are not needed.


For MDBs the possible cases are only these two - Either they execute in a transaction context or it is not supported.

RequiresNew, Mandatory, Never, Supports transaction attributes have behaviours which are dependent on if the client is using any existing transaction. Which is not possible for MDBs.

Regards,
Leena


[SCJP2, SCWCD1.3, SCBCD]
Binoj Viswanathan
Ranch Hand

Joined: Feb 25, 2003
Posts: 85
1. Yea, beforeCompletion () will be invoked by the container before the completion of the transaction. That means before either transaction rollback or transaction commit.


If txn is going to rollback beforeCompletion() wont b called by the container. onli calls this methd if the txn is going to commit.

thanx binoj


SCJP 1.4(98%)<br />SCBCD1.3 (100%)<br />SCWCD 1.4 (93%)(w/o prep..n)
amol deshpande
Ranch Hand

Joined: Sep 05, 2003
Posts: 162
hi ....

beforeCompletion is for stateful session with CMT only.....so u cannot use UserTransaction here.
This place is your last change to rollback the tx if you want to. So, if you think this tx is not good enough to be allowed to commit, you can do it here.
So I think its much use is going to be for rolllbacking last chance.


but container doesnt calll it if Tx is going to be rollbacked. So its much useful if you want to apply some logic and put Tx to rollback........your last chance as a B P.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Transactions