Software:
News ToolsReg Shops |
Migrating EJB 2.1 Entity and Session Beans to EJB 3.0The nuts and boltsPublished Tuesday 25th April 2006 06:02 GMT Table 2. EntityManager Class
In a session bean client class for EJB 3.0 entity bean, the @Resource private EntityManager em; An entity bean instance is created with the CatalogBean catalogBean=new CatalogBean(catalogId); em.persist(catalogBean); An entity bean instance is obtained with the
CatalogBean catalogBean=(CatalogBean)em.find("CatalogBean", catalogId);
A finder method may be defined corresponding to the named query
Query query=em.createNamedQuery("findByJournal");
Set the Query object parameters with the query.setParameter(0, journal); Obtain a java.util.Collection catalogBeanCollection=(CatalogBean)query.getResultList(); An entity bean instance is removed with the CatalogBean catalogBean; em.remove(catalogBean); The client class for the EJB 3.0 entity bean is listed in Listing 9. Listing 9. CatalogClient. EJB 3.0 Client Class
import javax.ejb.Stateless;
import javax.ejb.Resource;
import javax.persistence.EntityManager;
import javax.persistence.Query;
@Stateless
@Local
public class CatalogClient implements CatalogLocal {
@Resource
private EntityManager em;
public void create(String catalogId) {
CatalogBean catalogBean=new CatalogBean(catalogId);
em.persist(catalogBean);
}
public CatalogBean findByPrimaryKey(String catalogId) {
return (CatalogBean)em.find("CatalogBean", catalogId);
}
public java.util.Collection findByJournal(String journal) {
Query query=em.createNamedQuery("findByJournal");
query.setParameter(0, journal);
return (CatalogBean)query.getResultList();
}
public void remove(CatalogBean catalogBean) {
em.remove(catalogBean);
}
}
Track this type of story as a custom Atom/RSS feed or by email.
|
|
||||||||||||||||||||
Top 20 stories • All The Week’s Headlines • Archive • Search