• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Transactions

 
Emad El-Agouz
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sanju Thomas
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 351
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Binoj Viswanathan
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
amol deshpande
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic