• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What would happen if an onMessage method return before commiting a transaction?

 
Jingyi Wang
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What would happen if an onMessage method return before commiting a transaction? How about stateless session bean ?

thanks
 
Jason Hunt
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for MDB:
the container will log it, rollback the transaction and discard the bean instance

for slsb:
the container will do the 3 things mentioned above plus throw RemoteException or EJBException



 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jason is right If you want to go see what the spec exactly mentions, you can go to section 17.6.1:

If a stateless session bean instance starts a transaction in a business method, it must commit the transaction before the business method returns. The Container must detect the case in which a transaction was started, but not completed, in the business method, and handle it as follows:
  • Log this as an application error to alert the system administrator.
  • Roll back the started transaction.
  • Discard the instance of the session bean.
  • Throw the java.rmi.RemoteException to the client if the client is a remote client, or throw the javax.ejb.EJBException if the client is a local client.


  • If a message-driven bean instance starts a transaction in the onMessage method, it must commit the transaction before the onMessage method returns. The Container must detect the case in which a transaction was started, but not completed, in the onMessage method, and handle it as follows:
  • Log this as an application error to alert the system administrator.
  • Roll back the started transaction.
  • Discard the instance of the message-driven bean.

  •  
    Mina Syal
    Ranch Hand
    Posts: 31
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi,

    But what about SFSB as in case of SFSB, if a stateful session bean instance starts a transaction in a business method, it is not must to commit the transaction before the business method returns. Then how does Container detect the case in which a transaction was started but not completed and also what does container do if it detects such case?

    Thanks,
    Mina.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic