EJB life cycle method

This page discusses - EJB life cycle method

EJB life cycle method


The various stages through which an enterprise bean go through its lifetime is known as the life cycle of EJB. Each type of enterprise bean has different life cycle. Here we are telling you about the lifecycle of message driven bean. This type of bean follow three steps:

1)setMessageDrivenContext:-This method is used to pass the context object to the instance.

This method is generated automatically whenever a new enterprise bean is created.

At this stage the bean instance is ready to move for the garbage collection.

em.persist(newsEntity):-This method makes an entity instance that is managed and persistence.

em.merge(newsEntity):-By using this method we can merge the state of the given entity into the current persistence context.

em.remove(em.merge(newsEntity)):-This method is used for removing the entity instance.

Here is the program denoting life cycle of message driven bean.

package ejb;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

public class NewsEntityFacade implements NewsEntityFacadeLocal {
private EntityManager em;

public void create(NewsEntity newsEntity) {

public void edit(NewsEntity newsEntity) {

public void remove(NewsEntity newsEntity) {

Download source code

Share on Google+Share on Google+

EJB life cycle method

Posted on: April 18, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: EJB life cycle method  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image