Home Ejb EJB life cycle method
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

EJB life cycle method

Advertisement
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.

2)ejbCreate:-
This method is generated automatically whenever a new enterprise bean is created.

3)ejbRemove:-
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;

@Stateless
public class NewsEntityFacade implements NewsEntityFacadeLocal {
@PersistenceContext
private EntityManager em;

public void create(NewsEntity newsEntity) {
em.persist(newsEntity);
}

public void edit(NewsEntity newsEntity) {
em.merge(newsEntity);
}

public void remove(NewsEntity newsEntity) {
em.remove(em.merge(newsEntity));
}
}

Download source code

Advertisement

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

Ask Questions?    Discuss: EJB life cycle method  

Post your Comment


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

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