wood burning stoves 2.0*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Need Understanding of Transactional and Non-Transanctional Context 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 Understanding of Transactional and Non-Transanctional Context" Watch "Need Understanding of Transactional and Non-Transanctional Context" New topic
Author

Need Understanding of Transactional and Non-Transanctional Context

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

Source: EJB3.1 Spec.


4.6 Stateful Session Bean State Diagram

1.Based on the transaction attributes in the session bean's metadata annotations and/or deployment descriptor and the transaction context associated with the client's invocation, a business method is executed either in a transaction context or with an unspecified transaction context

2.A non-transactional method is executed while the instance is in the method ready state.

3.An invocation of a transactional method causes the instance to be included in a transaction. When the session bean instance is included in a transaction, the container issues the after-Begin method on it.


I understand a business method that is executed in transaction context ,is called as "transactional method" But still I am not unable to understand a few things here.

A.What does "transaction context" in the first statement means(theoretically & Programmatically) ?

B.What does the text"method ready state" from second statement "while the instance is in the method ready state" means ?

C.The third line says "An invocation of a transactional method causes the instance to be included in a transaction".
What does "instance to be included in a transaction" means here ?


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

Joined: Apr 07, 2010
Posts: 1687
    
  25

Hi Mohitkumar Gupta,

A.What does "transaction context" in the first statement means(theoretically & Programmatically) ?

A business method of a Stateful Session Bean runs in a transaction (depending on the Client and the TransactionAttribute) or without a transaction. The "context" of the method is either handled by a Transaction Manager or not.

B.What does the text"method ready state" from second statement "while the instance is in the method ready state" means ?

With a Stateful Session Bean you have two "method ready" states (have a look at the lifecycle diagram) :
  • "Method Ready"
  • "Method Ready in Transaction"

  • The instance that doesn't run in a transactional context operates in the "Method Ready" state

    C.The third line says "An invocation of a transactional method causes the instance to be included in a transaction".
    What does "instance to be included in a transaction" means here ?

    The Session Bean will now run in a transaction: either just started by the container (e.g. business method has a TransactionAttribute of REQUIRES_NEW), or recently started by the client invoking the business method (i.e. there will be more objects in the same transaction context, the client object and the Session bean)

    Note that the "Client" invoking a business method on a Session bean can just be another Session Bean.

    Regards,
    Frits
    Mohit G Gupta
    Ranch Hand

    Joined: May 18, 2010
    Posts: 634

    Hi Frits,

    Thanks for the reply But still I have couple of queries :

    A.What does "transaction context" in the first statement means(theoretically & Programmatically) ?

    A business method of a Stateful Session Bean runs in a transaction (depending on the Client and the TransactionAttribute) or without a transaction. The "context" of the method is either handled by a Transaction Manager or not.


    Q1. I understand that business method runs in a transaction or without a transaction
    But what is a "Transaction" and "Transaction context" .How can we define them?
    Suppose ShopCart is a Bean and business method is accessItems( access items from Bean).
    Then, can we say that the Transaction will be "accessing the items from ShopCart Bean" ?.

    With a Stateful Session Bean you have two "method ready" states (have a look at the lifecycle diagram) :
    "Method Ready"
    "Method Ready in Transaction"

    The instance that doesn't run in a transactional context operates in the "Method Ready" state


    Q2. What does "Method Ready" state means and How is it different from "Method Ready in Transaction" ?
    Frits Walraven
    Creator of Enthuware JWS+ V6
    Bartender

    Joined: Apr 07, 2010
    Posts: 1687
        
      25

    Suppose ShopCart is a Bean and business method is accessItems( access items from Bean).
    Then, can we say that the Transaction will be "accessing the items from ShopCart Bean" ?.

    You should see it like this: as soon as transactions are involved the container will request a Transaction Manager to look after all the steps needed in the transaction, making sure that al the ACID (Atomicity, Consistency, Isolation, Durability) requirements are met. If your accessItems business method (on lets say Session Bean A) requires a transaction, the transaction manager makes sure that all the work inside the business method is commited (or rolled back).

    If for instance accessItems on Session Bean A does a call to another Session Bean B and that one does a read on a database via an Entity Bean which signals that there is a problem. Session Bean B might to decide to "mark the transaction for rollback" because of the possibility of leaving a incorrect data behind. The transaction manager can now never let Session Bean A commit its work.

    Q2. What does "Method Ready" state means and How is it different from "Method Ready in Transaction" ?

    "Method Ready" means that the Session Bean can serve calls to business methods don't require a transaction (to be there or to be started).
    "Method Ready in Transaction" means that the Session Bean can serve calls to business methods that require a transaction

    Regards,
    Frits
    Mohit G Gupta
    Ranch Hand

    Joined: May 18, 2010
    Posts: 634

    You should see it like this: as soon as transactions are involved the container will request a Transaction Manager to look after all the steps needed in the transaction, making sure that al the ACID (Atomicity, Consistency, Isolation, Durability) requirements are met. If your accessItems business method (on lets say Session Bean A) requires a transaction, the transaction manager makes sure that all the work inside the business method is commited (or rolled back).

    If for instance accessItems on Session Bean A does a call to another Session Bean B and that one does a read on a database via an Entity Bean which signals that there is a problem. Session Bean B might to decide to "mark the transaction for rollback" because of the possibility of leaving a incorrect data behind. The transaction manager can now never let Session Bean A commit its work.


    I understand your answer ,but still I want to know what is a "Transaction" and "Transaction context" .How can we define them ?
    Frits Walraven
    Creator of Enthuware JWS+ V6
    Bartender

    Joined: Apr 07, 2010
    Posts: 1687
        
      25

    maybe this oracle document will help you understand.

    Regards,
    Frits
    Mohit G Gupta
    Ranch Hand

    Joined: May 18, 2010
    Posts: 634

    Thanks
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Need Understanding of Transactional and Non-Transanctional Context