Latest Tutorials| Questions and Answers|Ask Questions?|Site Map

Home Ejb EJB life cycle method

Related Tutorials


Share on Google+Share on Google+

EJB life cycle method

The various stages through which an enterprise bean go through its lifetime is known as the life cycle of EJB.

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


If you enjoyed this post then why not add us on Google+? Add us to your Circles

Liked it!  Share this Tutorial

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 12, 2009

Related Tutorials

Discuss: EJB life cycle method  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
May 4, 2012

thanx for this, it helped me for my xam........! keep it up