wood burning stoves*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Need Help on understanding Running EJB with Bean Managed 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 "Need Help on understanding Running EJB with Bean Managed Transactions" Watch "Need Help on understanding Running EJB with Bean Managed Transactions" New topic
Author

Need Help on understanding Running EJB with Bean Managed Transactions

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

Source:OCP JavaEE 6 EJB Developer Study Notes by Ivan A Krizsan Version: April 8, 2012


10.3.1. Example of an EJB with Bean Managed Transactions

As mentioned In the example, every third call to one and the same session bean instance will result in Rollback of the transaction.
On issuing third request to the Bean I was able to see the following in the logs:



Also,I was able to see the following result in the browser for the third request i.e http://localhost:8080/StatelessSessionWebTxn/test.do?name=John

Response from the EJB: Hello John, I am stateless session bean 1. The time is now: Sun Feb 24 12:39:35 IST 2013

As per my understanding,theMessage that holds the value for the message displayed on the browser is part of transaction.
Since,the transaction was roll-backed on third request,I should not have seen the message with name as John.(All the changes should be reverted)
Please advise on this.




OCPJP 6.0 93%
OCPJWCD 5.0 98%
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1630
    
  23

Hi Mohit,

As per my understanding,theMessage that holds the value for the message displayed on the browser is part of transaction.
Since,the transaction was roll-backed on third request,I should not have seen the message with name as John.(All the changes should be reverted)
Please advise on this.

No, the message is not a transactional resource (just a String)
  • If you would have sent the message on a Queue and the transaction was rolled-back then the message was removed (reverted) from the Queue.
  • If you would saved the message in a database and the transaction was rolled-back then the database update would also have been rolled-back.

  • Regards,
    Frits
    Mohit G Gupta
    Ranch Hand

    Joined: May 18, 2010
    Posts: 634

    Hi Frits,

    Thanks for the reply.
    Can please tell which resources are counted as transactional or where I can find more information about the resources that are transactional ?

    Frits Walraven
    Creator of Enthuware JWS+ V6
    Bartender

    Joined: Apr 07, 2010
    Posts: 1630
        
      23

    EJB specs 13.1.1 Transactions
    The terms resource and resource manager used in this chapter refer to the resources declared using the Resource annotation in the enterprise bean class or using the resource-ref element in the enterprise bean's deployment descriptor. This includes not only database resources, but also other resources, such as JMS Connections. These resources are considered to be "managed" by the container.


    and remember from EJB specs 4.2.2 The Effect of Transaction Rollback on Conversational State

    A session object's conversational state is not transactional. It is not automatically rolled back to its initial state if the transaction in which the object has participated rolls back. If a rollback could result in an inconsistency between a session object's conversational state and the state of the underlying database, the bean developer (or the application development tools used by the developer) must use the afterCompletion notification to manually reset its state.

    In other words: if you change an instance variable (of an EJB) in a transaction and the transaction is rolledback the instance variable is not put back to its original state and you as a bean provider has to do that yourself (for instance in the afterCompletion() method)

    Regards,
    Frits
    Mohit G Gupta
    Ranch Hand

    Joined: May 18, 2010
    Posts: 634

    Thanks Frits
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Need Help on understanding Running EJB with Bean Managed Transactions
     
    Similar Threads
    Hibernate/Derby; error message "Cannot close a connection while a transaction is still active"
    please answer this 128 questions for WLS. Urgently!
    How JTA Transaction work in the context of EJBs ?
    BMT and Session beans
    EJB transaction management?