Scenario: you have to migrate all of the EJB2 Entity Beans from a legacy project to EJB3 Entity Beans with JPA. Hibernate will be your JPA implementation and Spring Framework cannot be used. No other layer that the EJB2 Entity Beans layer will be migrated.
The application also contains an EJB2 Session Beans layer. This one will not be replaced, but updated to work with the new EJB3 Entity Beans. (Note: this article will not explain the J2EE architecture. If you want to find more about that, please check here . Please take the patterns presented in the link with a grain of salt. Some of them are obsolete, but some still make sense.)
Assumption: The 10K feet view of your legacy back end layers looks like below:
EmployeeDelegate: a Business Delegate pattern implementation and it is the only class that exposes the available functionality to a client. More about the Business Delegate pattern here .
initializeEmployeeSessionFacadeHome: a function that will locate and create the EmployeeSessionFacadeHome and return an EmployeeSessionFacade interface.
EmployeeSessionFacadeBean: the session facade that will actually contain the functionality exposed by EmployeeSessionFacade .
findEmployeeHome: is the function responsible for finding the EJB2 Entity Bean for working with employee data. This function will return EmployeeHome which is an interface.
EmployeeBean: is actually the class that contains the code to save and remove and work with employee data.
Now, the standard classes and interfaces of an Employee EJB2 CMP entity bean are shown below:
EmployeeHome: used to locate the bean and define the create and remove operations.
EmployeeBean: the entity bean that is actually managed by the container and implements the operations.
Employee: is the local interface of the bean.
EmployeeDTO: a data transfer object used to transfer data between various layers.
(Note: I will not detail here what an EJB 2 Entity Bean is or how it is configured.)
If you want to find out more about this subject, please check the official documentation .
Migrating Employee Bean From EJB 2.1 to EJB 3
This is assuming that you want to do this while keeping EmployeeSessionFacade as an EJB 2 session facade bean.
When migrating the new EJB 3 entity beans, I will try to expose the same functions as the old EJB 2 Entity Beans were exposing in order to minimize the changes in the other layers that are using that beans.
The specifications for EJB 3 Entity Beans also mention the Home Local and Remote interfaces.