• 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

How to get SessionContext ???

 
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a stateless session bean:

public class AdminSesssionBeanBean implements javax.ejb.SessionBean {
private javax.ejb.SessionContext mySessionCtx;

The bean is running, but i have a other class in the session bean where i need to get the SessionContext, how do i get the sessioncontext ???

SessionContext ctx = ???

Frank
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Frank,

What do you mean by "i have a other class in the session bean"? Do you have an inner class or another class within the same java file? You can solve your problem in two ways: one way is to pass the session context to the class� constructor, if it is instantiated inside of the session bean. Otherwise you can always define a business method like SessionContext getSessionContext() and have your private class calling it using normal jndi lookup, findByPrimaryKey(), etc. Because I doubt that session context object is serializable you can define this method only on the local interface. However you should ask yourself the obvious question how much sense does it make, from a designing perspective to define a business method that returns the session context? It would at least be acceptable if you could define an ejbHomeGetSessionContext() on the home interface, but this I guess is impossible since you need to return a reference to the current instance�s context.
Regards.
 
reply
    Bookmark Topic Watch Topic
  • New Topic