Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get SessionContext ???

 
Frank Jacobsen
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
  • 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
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic