wood burning stoves 2.0*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Bean Manage Transaction in Stateful Bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Bean Manage Transaction in Stateful Bean" Watch "Bean Manage Transaction in Stateful Bean" New topic
Author

Bean Manage Transaction in Stateful Bean

Amirr Rafique
Ranch Hand

Joined: Nov 14, 2005
Posts: 324
@Stateful
@TransactionManagement(BEAN)
public class TestBean implements Test
{
@Resource
private UserTransaction transaction;
public void someOperation(Timer timer)
{
transaction.begin();
// Do some logic here.
}
}
Which of the following statements are true regarding the above code?
a. The Container will automatically commit the transaction at the end of the method.
b. The Container will throw EJBException since the transaction is not ended.
c. The behavior of the above code will vary from Container to Container.
d. None of the above.

Why b is given as correct answer


"Know where to find the solution and how to use it - that's the secret of success."
Lee Kian Giap
Ranch Hand

Joined: Jan 23, 2008
Posts: 213
Although it is NOT MUST for a STATEFUL Session Bean instance to commit/rollback a transaction before the business method returns ( the business method that transaction begin() ). It is a MUST to commit/rollback a transaction at the last business method returns of the whole transaction (since stateful session bean might have multiple client call, which most probably in different business method), because every transaction have its transaction demarcation/boundaries.

so for these question, since there is only one method in the TestBean class, the transaction completed in the same method it begin. Having no commit() in that method, will cause a system exception to be thrown, which is wrapped in EJBException. (exception which is RemoteException and RuntimeException is wrapped in EJBException)


Please correct me if I am wrong , thank y


SCJP 6, SCWCD 5, SCBCD 5
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

Hi

IMHO you deal here with a BTM and in this case you (or more precisely the bean) are (is) responsible for the transaction life cycle. So if you start it you must also end it (commit it).

Regards,
Mihai


SCJP, SCJD, SCWCD, OCPJBCD
Krzysztof Koziol
Ranch Hand

Joined: Nov 19, 2006
Posts: 133

Hello,

Taking into consideration a statefull bean with a EXTENDED persistence context do we also have to commit the user transaction in each single method?

Regards


SCJP 5.0, SCWCD 5.0, SCBCD 5.0, SCEA/OCMJEA 5.0
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

Krzysztof,


Why do you think about extended persistence context ? The only relation is the fact that extended persistence context can be used only with SFSB this is a feature but not a must. In this example there is no persistence context.

Regards,
Mihai
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Bean Manage Transaction in Stateful Bean