Online Hibernate Training just in Rs. 1000

One week online training in Hibernate ORM framework. Learn Hibernate Framework and enhance your skills. Best Online Hibernate training at 90% discount. Join Now!! Offer is valid Only for limited Period!!! Online Training

EJB create method

In this tutorial we are describing you about the EJB create method. The create() method is used for creating the EJBean.

Ads

EJB create method

     

In this tutorial we are describing you about the EJB create method. The create() method is used for creating the EJBean. The other methods which are used in the program given below .

 private EntityManager em:-Defines an Interface instance. The interface Entity manager is associated with the persistence context.

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

em.merge(newsEntity):-This method merge the state of the given entity into the current persistence context.

em.remove(em.merge(newsEntity)):-By using this method we can remove the entity instance.

 em.find(ejb.NewsEntity.class, id):-This methods find the entity instance by the primary key. Here primary key is id.

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));
  }

  public NewsEntity find(Object id) {
  return em.find(ejb.NewsEntity.class, id);
  }

  public List findAll() {
  return em.createQuery("select object(o) from NewsEntity as o")
   .getResultList
();
  }

}

Download source code

Advertisements

Share on Google+Share on Google+

EJB create method

Posted on: January 12, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: EJB create method  

Post your Comment


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

Ads

 

Ads