File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Regarding Tx and Security Context for Interceptor method 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 "Regarding Tx and Security Context for Interceptor method" Watch "Regarding Tx and Security Context for Interceptor method" New topic
Author

Regarding Tx and Security Context for Interceptor method

Juggy Obhi
Ranch Hand

Joined: Jul 02, 2007
Posts: 51
Hi,

Consider we have a client with Transaction context T1 calling a Business method of a Bean with Transaction Context T2. There is one interceptor method associated with the business method.

I want to know in what Transaction Context Interceptor method would get called with T1 or T2? Since in the Books it is mentioned that Interceptor method executes in the same Transaction Context as of the Business method for which it is called.

Another think that i need to know is, in what Transaction Context the Interceptor method would get called with for a BMT Bean.
Since the Transaction Context is not marked outside the busniess method it is defined somewhere within the Bean. How do Container understand in what Transaction Context to perform the execution of Interceptor method in without touching the internals of the Business method. Since the Tx context detail is not marked as annotation above the method.

Please Guide.


It does not matter how many times you fall,what matters is how many times you stand back.
Sergio Tridente
Ranch Hand

Joined: Mar 22, 2007
Posts: 329

Originally posted by Juggy Obhi:
I want to know in what Transaction Context Interceptor method would get called with T1 or T2? Since in the Books it is mentioned that Interceptor method executes in the same Transaction Context as of the Business method for which it is called.


It would be called in the context of the bean's business method transaction, T2

Originally posted by Juggy Obhi:
Another think that i need to know is, in what Transaction Context the Interceptor method would get called with for a BMT Bean.
Since the Transaction Context is not marked outside the busniess method it is defined somewhere within the Bean. How do Container understand in what Transaction Context to perform the execution of Interceptor method in without touching the internals of the Business method. Since the Tx context detail is not marked as annotation above the method.


It wil be called with no transaction.


SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)
Juggy Obhi
Ranch Hand

Joined: Jul 02, 2007
Posts: 51
Does this mean that an interceptor method for BMT Bean always executes in an unspecified transaction and security context? Is there any case where this is not true?

The picture is quite clear to me now. Thank You

[ September 25, 2008: Message edited by: Juggy Obhi ]
[ September 25, 2008: Message edited by: Juggy Obhi ]
Sergio Tridente
Ranch Hand

Joined: Mar 22, 2007
Posts: 329

Originally posted by Juggy Obhi:
Is there any case where this is not true?


Yes, you can begin and/or end your transaction in the interceptor method itself.
ruijin yang
Ranch Hand

Joined: Apr 29, 2001
Posts: 96
Hi,

Is this a nested transaction? EJB architecture does not support nested transaction.


Originally posted by Juggy Obhi:
Hi,

Consider we have a client with Transaction context T1 calling a Business method of a Bean with Transaction Context T2. There is one interceptor method associated with the business method.

I want to know in what Transaction Context Interceptor method would get called with T1 or T2? Since in the Books it is mentioned that Interceptor method executes in the same Transaction Context as of the Business method for which it is called.

Another think that i need to know is, in what Transaction Context the Interceptor method would get called with for a BMT Bean.
Since the Transaction Context is not marked outside the busniess method it is defined somewhere within the Bean. How do Container understand in what Transaction Context to perform the execution of Interceptor method in without touching the internals of the Business method. Since the Tx context detail is not marked as annotation above the method.

Please Guide.


SUN Certified Business Component Developer Java EE Platform 5 (2008)<br />SUN Certified Developer for Java Web Services (2007)<br />IBM WebSphere Portal V5.1 Application Development (2006)<br />SUN Certified Web Component Developer (2001)<br />SUN Certified Java 2 Programmer (2001)
Juggy Obhi
Ranch Hand

Joined: Jul 02, 2007
Posts: 51

Is this a nested transaction? EJB architecture does not support nested transaction.


EJB do not support Nested Transaction. EJB supports FLAT Transaction. You can't have more than one Active transaction at the same time.

Flat Transaction

This is not a nested Transaction because when a transaction context T1 is received from the client either is gets carried forward (@Support,@Required) or gets STOP/Suspended so that T2 can pe performed. You will not have any case where T1 and T2 are both Active.


Yes, you can begin and/or end your transaction in the interceptor method itself.


I want to clarify one doubt. It is said that for a Stateful Session bean method committing a transaction is optional while for Stateless it is mandatory.

Will this rule apply to Interceptor method also? Like for an Interceptor method of a stateful bean its is optional to commit/end a transaction at the end of the method and for an interceptor method to a stateless session bean method it is mandatory?
Sergio Tridente
Ranch Hand

Joined: Mar 22, 2007
Posts: 329

Originally posted by Juggy Obhi:


I want to clarify one doubt. It is said that for a Stateful Session bean method committing a transaction is optional while for Stateless it is mandatory.

Will this rule apply to Interceptor method also? Like for an Interceptor method of a stateful bean its is optional to commit/end a transaction at the end of the method and for an interceptor method to a stateless session bean method it is mandatory?


Refer to section 13.6.1 of the ejb core specification:


In the case of a stateful session bean, it is possible that the business method that started a transaction completes without committing or rolling back the transaction. In such a case, the container must retain the association between the transaction and the instance across multiple client calls until the instance commits or rolls back the transaction. When the client invokes the next business method, the container must invoke the business method (and any applicable interceptor methods for the bean) in this transaction context.

If a stateless session bean instance starts a transaction in a business method or interceptor method, it must commit the transaction before the business method (or all its interceptor methods) returns.

[ September 26, 2008: Message edited by: Sergio Tridente ]
Juggy Obhi
Ranch Hand

Joined: Jul 02, 2007
Posts: 51
I got the concept
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding Tx and Security Context for Interceptor method