• Post Reply Bookmark Topic Watch Topic
  • New Topic

SessionContext  RSS feed

 
Nupur Gupta
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In an EJB, how is a SessionContext useful?

Thanks a lot.
 
Mahesh Desai
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using the SessionContext reference, the bean interacts with the container throughout the lifecycle of the bean.

Thanks,
Mahesh
 
Nupur Gupta
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mahesh... yes I know it interacts... but how? I mean, what are the useful things that are done... i mean i looked up the sessioncontext api, and it didnt look very functional....
 
Sunil Dixit
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nupur,
Let me explain you why any implementation of EJBContext (i.e. sessioncontext or entitycontext) is important. As Mahesh told you that'bean instance interacts with the container throughout the lifecycle'.
1. Using this object you commit/rollback you Tx
2. You can get the PK (if it is entity bean)
3. Using that you get UserTranscationObject which is used to handle User
Manager Tx.
4. You can get the user Principal object which tells you credential user has
given to i.e. some time if you want that some method of your ejb shd be
called when user has some role/credentials that you use that object.
{when you want to do this thinh via code}
5. You can get the reference of your EJBObject/Local Object.
6. you can also use that object to check whether user has cretain role
before user call any method ?

Hope that I am able to give the answer.

Cheers,
Sunil Dixit
 
Aaron Raja
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EJBContext:
Every bean obtains an EJBContext object, which is a reference directly to the container. The EJB can request information about its environment like the status of a transaction, a remote reference to itself (an EJB cannot use �this� to reference itself) etc.
 
Aaron Raja
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me say this in simple way !!!
EJBContext--> Every bean obtains an EJBContext object, which is a reference directly to the container. It provides methods for interacting with the container so that the bean can request information about its environment like the identity of the caller, security, status of a transaction, obtains remote reference to itself etc. e.g. isUserInRole(), getUserPrincipal(), isRollbackOnly(), etc
The EJB can request information about its environment like the status of a transaction, a remote reference to itself (an EJB cannot use �this� to reference itself) etc.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!