Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
I find this confusing because transactions don't span multiple methods in the case of CMT stateful session beans also. Then why is it that this interface can only be implemented by them ?
Suman A Sarker<br />SCJP, SCWCD, SCBCD<br /> <br />If You Can't Beat Them ... Join Them!
I know this point, my question is why it can't be implemented by stateless session beans. Anyway for both stateless and CMT stateful beans, transactions don't span multiple methods. Then whats the difference ?
Suman A Sarker<br />SCJP, SCWCD, SCBCD<br /> <br />If You Can't Beat Them ... Join Them!
A stateful session bean can span transactions even across different method invocations on the same bean.
Originally posted by Vipin Mohan:
Dear Ramesh & Suman
Thanks for your answers. I have some confusion even now.
You have said that
However, on page 509 of Head First EJB, it is stated that
"CMT transactions cannot stay open across multiple method invocations from a stateful session client."
Please advice.
Thanks
Vipin
A stateful session bean can span transactions even across different method invocations on the same bean.
Suman A Sarker<br />SCJP, SCWCD, SCBCD<br /> <br />If You Can't Beat Them ... Join Them!
Originally posted by Vipin Mohan:
Thanks Suman !
But I still feel that I'm missing something about CMT stateful beans here.
The API states that
"The afterBegin method notifies a session Bean instance that a new transaction has started, and that the subsequent business methods on the instance will be invoked in the context of the transaction. "
But in Head First EJB, it is said that "CMT transactions cannot stay open across multiple method invocations from a stateful session client."
Don't you find these statements contradictory ?
And the statement "Only stateful session beans can implement SessionSynchronization, because stateless session beans are not allowed to maintain a transaction once a method has ended."
seems to support the first statement and contradict the second.
Can you advice ?
Thanks so much
Vipin
From your explanation, I understand that the following statement from Head First EJB is incorrect - "CMT transactions cannot stay open across multiple method invocations from a stateful session client."
Suman A Sarker<br />SCJP, SCWCD, SCBCD<br /> <br />If You Can't Beat Them ... Join Them!
Suman A Sarker<br />SCJP, SCWCD, SCBCD<br /> <br />If You Can't Beat Them ... Join Them!
In this example, if the invoke1() method has a 'RequiresNew' transaction attribute, then the transaction of someMethod1() would be suspended and this transaction would proceed. Thats how 'RequiresNew' works, right?
If a session bean instance is participating in a transaction, it is an error for a client to invoke a method on the session object such that the transaction attribute in the deployment descriptor would cause the container to execute the method in a different transaction context or in an unspecified transaction context. In such a case, the container throws the java.rmi.RemoteException to the client if the client is a remote client, or the javax.ejb.EJBException if the client is a local client.
Suman A Sarker<br />SCJP, SCWCD, SCBCD<br /> <br />If You Can't Beat Them ... Join Them!
Suman A Sarker<br />SCJP, SCWCD, SCBCD<br /> <br />If You Can't Beat Them ... Join Them!
Originally posted by Vipin Mohan:
hi Suman
Yes, now I'm clear with the whole concept, thanks to you and Ramesh.
It was a very useful discussion.
Thanks again for your time.
Cheers
Vipin
Thanks Suman !
But I still feel that I'm missing something about CMT stateful beans here.
The API states that
"The afterBegin method notifies a session Bean instance that a new transaction has started, and that the subsequent business methods on the instance will be invoked in the context of the transaction. "
But in Head First EJB, it is said that "CMT transactions cannot stay open across multiple method invocations from a stateful session client."
Don't you find these statements contradictory ?
And the statement "Only stateful session beans can implement SessionSynchronization, because stateless session beans are not allowed to maintain a transaction once a method has ended."
seems to support the first statement and contradict the second.
Can you advice ?
Thanks so much
Vipin
If a session bean instance is participating in a transaction, it is an error for a client to invoke a method on the session object such that the transaction attribute in the deployment descriptor would cause the container to execute the method in a different transaction context or in an unspecified transaction context. In such a case, the container throws the java.rmi.RemoteException to the client if the client is a remote client, or the javax.ejb.EJBException if the client is a local client.
Don't get me started about those stupid light bulbs. |