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 In this tutorial, migration of EJB 2.1 specification EJBs to EJB 3.0 specification is discussed. EJB 3.0 Session and Entity beans require JDK 5.0 as metadata annotations are used in the specification. The EJB 2.1 specification is implemented in the An EJB 3.0 session bean class is a POJO (Plain Old Java Object – Martin Fowler) and does not implement the An EJB 2.1 session bean class includes one or more An EJB 3.0 session bean class includes only the business methods. A home interface in an EJB 2.1 session EJB extends the An EJB 2.1 session EJB includes a deployment descriptor that specifies the EJB name, the bean class name, and the interfaces. The deployment descriptor also specifies the bean type of Stateless/Stateful. In EJB 3.0 a deployment descriptor is not required for a session bean. An EJB 2.1 Entity EJB bean class implements the In comparison, an EJB 3.0 entity bean class is a POJO which does not implement the The values specified in the EJB 2.1 deployment descriptor are included in EJB 3.0 bean class with JDK 5.0 annotations. Thus, the number of classes/interfaces/deployment descriptors is reduced in the EJB 3.0 specification. In this tutorial we shall migrate an example Session EJB and an example Entity EJB from EJB 2.1 to EJB 3.0 specification. IntroductionThe purpose of the Enterprise JavaBeans EJB 3.0 specification is to improve the EJB architecture by reducing its complexity from the developer's point of view. EJB 3.0 is implemented by different application servers such as those from JBoss, Oracle and Caucho. The implementation in the different application servers may vary. In this tutorial an example session bean and an example entity bean are migrated from EJB 2.1 to EJB 3.0 specification. Migration from EJB 2.0 is similar. Migrating a Session BeanIn this section we shall migrate an example stateless session bean from EJB 2.1 specification to EJB 3.0 specification. The session bean class implements the Listing 1. CatalogBean.java EJB 2.1 Session Bean
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
public class CatalogBean implements SessionBean{
private SessionContext ctx;
public String getJournal(String publisher){
if (publisher.equals("Oracle Publisher"))
return new String("Oracle Magazine");
if (journal.equals("OReilly"))
return new String("dev2dev");
}
public void ejbCreate(){}
public void ejbRemove() {}
public void ejbActivate() {}
public void ejbPassivate() {}
public void setSessionContext(SessionContext ctx) {this.ctx=ctx;}
}
In EJB 3.0, metadata annotations are used to specify the session bean type and local and remote business interfaces. A stateless session bean is specified with annotation The EJB 3.0 session bean corresponding to the EJB 2.1 stateless session bean is annotated with the metadata annotation
Track this type of story as a custom Atom/RSS feed or by email.
|
Developer HeadlinesThe UK's latest developer news from MSDN |
Top 20 stories • All The Week’s Headlines • Archive • Search