• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Session Transaction Confusion

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In HeadFirstEJB p.508 : "Stateless session beans must complete a transaction by the end of the business method in which the transaction was started". Will the following be legal for a stateless session BMT bean :

private UserTransaction ut;

public void mainMethod(){
ut = context.getUserTransaction() ;
this.subMethod() ;
ut.commit();
}

private void subMethod(){
ut.begin();
}

If the above is not legal, what exception will be thrown ?
Thanks for any advices.
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you have written is illegal for a SLSB. The container will detect this and do the following:
Log this as an application error to alert the system administrator.
Roll back the started transaction.
Discard the instance of the session bean.
Throw the java.rmi.RemoteException to the client if the client is a remote client, or throw the javax.ejb.EJBException if the client is a local client.
 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
The container will throw javax.txn.NotSupportedException
binoj
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Binoj Viswanathan:
Hi,
The container will throw javax.txn.NotSupportedException
binoj



javax.transaction.NotSupportedException is a checked exception thrown by UserTransaction.begin() method. So this exception, must be either be handled or declared in


private void subMethod(){
ut.begin();
}
(John Tao code snippet)



If the exception was handled in subMethod() or mainMethod() then, it would wrap and throw it as an EJBException to the container. The container in turn will throw it as RemoteException (if remote) or EJBException (if local) to the client. Hence the client will see it as RemoteException or EJBException.

I would say that javax.transaction.NotSupportedException is an unexpected exception in the client point of view, as the client need not know what type of transaction is used in the bean (Flat Transaction or Nested Transaction).
(In reference to Page 543 of HFEJB)
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic