Session Bean

Find below are the list of annotations with description to develop and deploy Stateless and Statful Session Bean.
Software required :

Annotations are used in Session Bean :

  • @Local (javax.ejb.Local) : Declares the local business interface for a session bean
  • @Remote (javax.ejb.Remote) :Declares the remote business interface for a session bean
  • @Stateless (javax.ejb.Stateless) :Defining annotation for a stateless session bean
  • @Stateful (javax.ejb.Stateful) :Defining annotation for a stateful session bean

Life cycle event handlers in Session Bean :

  • @PostConstruct (javax.annotation.PostConstruct) :
    • The annotated method is called by the container immediately after a bean instance is instantiated.
    • This annotation is applicable to both stateless and stateful session beans.
  • @PreDestroy (javax.annotation.PreDestroy) :
    • The annotated method is called before the container destroys an unused or expired bean instance from its object pool.
    • This annotation is applicable to both stateless and stateful session beans.
  • @PrePassivate (javax.ejb.PrePassivate) :
    • If a stateful session bean instance is idle for too long, the container might passivate it and store its state to a cache.
    • The method tagged by this annotation is called before the container passivates the bean instance.
    • This annotation is only applicable to stateful session beans.
  • @PostActivate (javax.ejb.PostActivate):
    • When the client uses the passivated stateful session bean again, a new instance is created and the bean state is restored.
    • The method tagged this annotation is called when the activated bean instance is ready.
    • This annotation is only applicable to stateful session beans.
  • @Init: (javax.ejb.Init)
    • This annotation designates initialization methods for a stateful session bean.
    • It is different from the @PostConstruct annotation in that there can be multiple methods tagged with @Init in a stateful session bean. However, each bean instance can only have one @Init method invoked.
    • The EJB 3.0 container determines which @Init method to invoke depending on how the bean is created.
    • The @PostConstruct method is called after the @Init method.
  • @Remove (javax.ejb.Remove) :
    • Applied to a business method of a stateful session bean class
Previous Next

Comment by : shilpa October 22nd, 2012
Comment : stateless session bean


Write your Comment

Name :
Email Id : [ We will not publish your email id ]
Your Comment : [ Maximum 200 chars ]
Enter Security code