Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Enterprise JavaBeans 3.0 simplifies the enterprise bean architecture and provides enhanced and more powerful features. The new specification leverages the annotations metadata facility introduced in Java 5, persistence and object-relational mapping best practices from tools such as Hibernate and TopLink, and the Dependency Injection pattern made popular by lightweight Java frameworks such as Spring.
This article discusses possible migration strategies for moving applications written using EJB 2.1 or an earlier specification to an EJB 3.0-based architecture. The possible migration paths are evaluated from both the perspectives of design and implementation. This article does not intend to be exhaustive in illustrating the migration options. After reading this article, you should be able to choose the best option, within your own specific context, for migrating the legacy EJB code to the new specification.
This article assumes you are familiar with the enterprise bean, Java 5, and object-relational mapping features and concepts.
To provide a context for this article's discussion of possible migration paths, I begin by discussing the changes in the new specification in the context of each of the different bean types and then at a generic level pertinent across multiple bean types.
In EJB 2.1 and earlier specifications, two interfaces—the home and the local, or remote, business interfaces—and the bean
implementation class were required for each session bean. The home interface was required to extend the EJBHome or the EJBLocalHome interface and declare the lifecycle method, such as create(). The local, or remote, business interface was required to extend the EJBObject or the EJBLocalObject interface and declare the business methods. The bean implementation class itself was an EnterpriseBean type and, in the case of session beans, extended the SessionBean sub-interface. Callback method implementations in the bean class had to be provided so that the container could trigger them
on occurrence of the appropriate lifecycle events. In addition, critical elements of the bean, including its transaction and
security definition, and whether it was stateful or stateless, were defined in the associated deployment descriptors.
Listing 1 illustrates an example of a stateful session bean defined using the EJB 2.1 specification.
Listing 1. An EJB 2.1-based banking service stateful session bean
public interface BankingService extends EJBObject {
public void deposit(int accountId, float amount) throws RemoteException;
public void withdraw(int accountId, float amount)throws RemoteException;
public float getBalance(int accountId) throws RemoteException;
public void doServiceLogout() throws RemoteException;
}
public interface BankingServiceHome extends EJBHome {
public BankingService create() throws CreateException, RemoteException;
}
public class BankingServiceEJB implements SessionBean {
public void deposit(int accountId, float amount) throws RemoteException {
//Business logic to deposit the specified amount and update the balance
}
public void withdraw(int accountId, float amount)throws RemoteException {
//Business logic to withdraw the desired amount and update the balance
}
public float getBalance(int accountId) throws RemoteException {
//Business logic to get the current balance
}
public void doServiceLogout() throws RemoteException {
//Service completion and logout logic
}
public void ejbCreate(){}
public void ejbActivate(){}
public void ejbPassivate(){}
public void ejbRemove(){}
public void setSessionContext(SessionContext context){}
}
In the EJB 3.0 specification, a session bean needs to define only a business interface and a bean implementation class. The
home interface has been removed. The business interface is a regular Java interface, also sometimes called POJI, or the plain-old Java interface. The business interface does not need to extend the EJBObject or the EJBLocalObject interface; instead, if required, it could be defined within the interface hierarchy that represents the business domain model.
Archived Discussions (Read only)