• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Bean Manage Transaction in Stateful Bean

 
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@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
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 133
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic