Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Meaning of Transaction-type under ejb-jar.xml is set to Container ??

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

We are using MessageDrivenBeans and on to its onMessage Method we are using the try catch and finally blocks .

(As to my knowledge this means that the transactions are handled by the developer )


But when i see on to the ejb-jar.xml the transaction-type is set to Container .

Please throw me some light as who is handling the transactions in this case ??

Thanks in advance .


 
Christian Gossart
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ravi,

If you have in your deployment descriptor, this will override the corresponding annotation for the enterprise bean. So in your case, the EJB container is handling the transaction, even if your MDB is annotated with A transaction is opened by the container immediately before any call to onMessage, and commited/closed immediately after, unless a system exception is thrown, or the setRollbackOnly method is called on the EJBContext.
Using try/catch/finally does not imply the transaction is being handled by the developer, only that you're dealing with exception coming from your business layer (or anything invoked by your MDB).

To handle yourself the transaction, you have to remove the ejb-jar.xml fragment for this MDB (or set the transaction type to BEAN), and use the TransactionManager interface to begin(), commit() or rollback() the transaction in your code.

You'll find more information on transaction management there: http://java.sun.com/javaee/5/docs/tutorial/doc/bncii.html


Regards,

 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi Kiran V wrote:Hi ,

We are using MessageDrivenBeans and on to its onMessage Method we are using the try catch and finally blocks .

(As to my knowledge this means that the transactions are handled by the developer )


Why do you think so?


But when i see on to the ejb-jar.xml the transaction-type is set to Container .

Please throw me some light as who is handling the transactions in this case ??


The container.

ram.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using try/catch/finally does not imply the transaction is being handled by the developer, only that you're dealing with exception coming from your business layer (or anything invoked by your MDB).


Thanks for this line Christian Gossart .It was indeed very helpful .

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic