Migrate WebSphere Commerce Version 8 EJB entity beans to Java Persistence API
Enterprise Java Entity Beans are no longer supported in WebSphere Commerce Version 9. By using a combination of tools and manual steps, we can migrate your EJB 1.1 entity beans to JPA, and update your code to use WebSphere Commerce Version 9 APIs. The well-established Java Persistence API (JPA) has numerous advantages, including simplicity and speed. To take advantage of JPA technology, we can use the Code Migration Tool to help you migrate existing beans to JPA. The Code Migration Tool scans EJB beans and identifies entities and code that need to be updated to the JPA specification. Where possible, the tool can perform substitutions, such as class, exception, and method name changes and removals. Where it is unable to make any changes, the utility logs what is found.Note: Stateless Session EJBs are still supported and do not need to be migrated to JPA.
Before beginning
Export the following two projects from the WebSphere Commerce Version 8 development environment to the WebSphere Commerce Version 9.0.0.1+ development environment.
- WebSphereCommerceServerExtensionsData
- WebSphereCommerceServerExtensionsLogic
Task info
The migration of your EJB 1.1 entity beans to JPA involves modifying two projects within the WebSphere Commerce Version 9.0.0.1+ development environment:
- WebSphereCommerceServerExtensionsData
- To migrate this project, we can use a combination of tools. You start by leveraging Rational Application Developer (RAD) to generate JPA entities from the database schema. We can then identify and correct any remaining errors that occurred from the JPA generation that is performed by RAD.
- WebSphereCommerceServerExtensionsLogic
- To migrate this project, we can manually convert EJB data beans to JPA data beans, and convert command classes to use JPA code, then use the Code Migration Tool to identify and correct any remaining errors that occurred from the manual conversions.
Procedure
- Migrate our custom EJB 1.1 EJBs and AccessBeans to JPA by using either the WC-JPA-Modeler, or the manual method.
- For the WC-JPA-Modeler, download, install, and run the tool.
- For the manual method, complete the following steps.
- By using RAD, generate JPA entities from the database schema for the WebSphereCommerceServerExtensionsData project.
- Open Rational Application Developer.
- Right-click WebSphereCommerceServerExtensionsData, then click Rename.
- Back up the project by renaming it to something else, for example, WebSphereCommerceServerExtensionsData-EJB.
- Right-click the WC project, then click Properties > Deployment Assembly to change what is included in the Enterprise Archive (EAR).
- Click the WebSphereCommerceServerExtensionsData project that you renamed, for example, WebSphereCommerceServerExtensionsData-EJB. Then, click Remove > OK.
- Click File > New > JPA Project.
- For the project name, enter WebSphereCommerceServerExtensionsData.
- In the EAR membership section, click Add project to an EAR, select WC for our EAR project name, then click Finish.
If we are using asked to change the perspective to the JPA perspective, click Yes.
- Switch to your Data source Explorer.
- Right-click Database Connections, then click New.
- Select a database manager:
- (DB2) For DB2 for Linux, UNIX, and Windows:
- Select JDBC driver IBM Data Server Driver for JDBC and SQLJ (JDBC 4.0) Default.
- Complete the fields for Database, Host, Port number, User name, Password, and Default schema.
- Click Finish.
- (Oracle) For Oracle:
- Select JDBC driver Oracle 12 - Oracle Thin Driver Default.
- Click the ellipsis button (...) next to the JDBC driver, add or edit your JDBC driver, then click Ok.
- Fill out SID, Host, Port number, User name, Password, Default schema.
- Click Finish.
- Right-click the JPA project in the Project Explorer, then click JPA Tools > Generate Entities from Tables.
- On the Select tables page of the Generate Entities from Tables wizard, select the database connection createdd.
- Complete the wizard, then click Finish.
- Build your project by clicking Projects > Build All.
- Convert your EJB data beans to JPA data beans in the WebSphereCommerceServerExtensionsLogic project.
- Open a data bean class.
- Remove the references to the methods removed in the WebSphereCommerceServerExtensionsData project.
- Remove code references to the following exceptions by removing them from throws clauses in method declarations, and removing catch clauses that catch them.
- java.rmi.RemoteException
- javax.naming.NamingException
- Replace code references to the following exceptions by the appropriate javax.persistence.PersistenceException subclass by replacing them in throws clauses in method declarations, and replacing catch clauses that catch them.
- javax.ejb.CreateException
- javax.ejb.FinderException
- Find all references to the setEJBRef(...) method and update the method name to setEntity.
- Find all references to .getEJBRef().remove() and update them to: .remove().
- Find all references to the getEJBRef() method and update the method name to getEntity.
- Repeat these substeps for all of your data bean classes.
- Convert your command classes to use JPA code in the WebSphereCommerceServerExtensionsLogic project.
- Open a command class.
- Remove the references to the methods removed in the WebSphereCommerceServerExtensionsData project.
- Remove code references to the following exceptions by removing them from throws clauses in method declarations, and removing catch clauses that catch them.
- java.rmi.RemoteException
- javax.ejb.CreateException
- javax.ejb.FinderException
- javax.naming.NamingException
- Update the logic to coincide with JPA.
- Repeat these substeps for every command class.
- Update all references to the default EJB 1.1 EJBs and AccessBeans to JPA by using either the wc-code-migration-tool, or the manual method.
- For the wc-code-migration-tool, download, install, and run the wc-code-migraion-tool.
- If you would rather manually update your projects, the following tables outline specific pieces of code that the Code Migration Tool checks. By using the following table as a reference, we can work through each table, making the required changes as you go.
Change all uses of any class of the form To com.ibm.commerce.*BeanFinderObject com.ibm.commerce.*QueryHelper. com.ibm.commerce.*BeanFinderObjectBase com.ibm.commerce.*QueryHelperBase. com.ibm.commerce.base.objects.JDBCFinderObject com.ibm.commerce.base.objects.QueryHelper. com.ibm.commerce.*BeanBase com.ibm.commerce.*EntityBase. com.ibm.commerce.base.objects.ECEntityBean com.ibm.commerce.base.objects.EntityBase. com.ibm.commerce.*BeanAccessHelper com.ibm.commerce.*AccessHelper.
Remove all uses of: Additional notes: com.ibm.commerce.*AccessBeanData None com.ibm.commerce.*Key Where it represented a primary key that is composed of only a single column in the corresponding table. com.ibm.commerce.*JDBCHelper Including any class that also had javax.ejb.EJBObject as a superclass com.ibm.commerce.*JDBCHelperAccessBean None com.ibm.commerce.*JDBCHelperFactory None com.ibm.commerce.*JDBCHelperHome None com.ibm.commerce.*Home. Replace it using the appropriate JPA entity directly, or use the corresponding AccessBean class. com.ibm.commerce.*AccessBeanData None
- javax.naming.NamingException
- java.rmi.RemoteException
Where these exceptions were thrown by methods in WebSphere Commerce Version 8.
- javax.ejb.CreateException
- javax.ejb.FinderException
Where these exceptions were thrown by methods in WebSphere Commerce Version 8. Replace these by the appropriate javax.persistence.PersistenceException subclass. javax.ejb.DuplicateKeyException Where these exceptions were thrown by methods in WebSphere Commerce Version 8. Replace these exceptions with javax.persistence.EntityExistsException. ejbCreate() From any class of the form com.ibm.commerce.* ejbPostCreate() From any class of the form com.ibm.commerce.*BeanBase. ejbPostCreate() From any class of the form com.ibm.commerce.*BeanAccessHelper. getSessionContext() From any class of the form com.ibm.commerce.*. ejbActivate() From any class of the form com.ibm.commerce.*. ejbCreate() From any class of the form com.ibm.commerce.*. ejbPassivate() From any class of the form com.ibm.commerce.*. ejbRemove() From any class of the form com.ibm.commerce.*. instantiateEJBByPrimaryKey() From any class of the form com.ibm.commerce.*AccessBean. defaultJNDIName() From any class of the form com.ibm.commerce.*AccessBean. commitCopyHelper() From any class of the form com.ibm.commerce.*AccessBean. refreshCopyHelper() From any class of the form com.ibm.commerce.*AccessBean. copyFields() From any class of the form com.ibm.commerce.*EntityCreationData. getMemorySizeExcludingObjectsToScrub() From any class of the form com.ibm.commerce.*Key. getObjectsToScrub() From any class of the form com.ibm.commerce.*Key. getObjectSize() From any class of the form com.ibm.commerce.*Key. setScrubbedObjects() From any class of the form com.ibm.commerce.*Key. getObjectModelFacade() From any class of the form com.ibm.commerce.*. getOMF() From any class of the form com.ibm.commerce.*. getObjectModuleFacade() From any class of the form com.ibm.commerce.*. getPPCJDBCHelper() From any class of the form com.ibm.commerce.*. getPaymentsFacade() From any class of the form com.ibm.commerce.*. getActivityLoggerFacade() From any class of the form com.ibm.commerce.*. get*InEJBType() From any class of the form com.ibm.commerce.*. Replace with get*InEntityType. instantiateEJB() From any class of the form com.ibm.commerce.*AccessBean. Replace with instantiateEntity. Reads and Writes of all public fields in classes of the form com.ibm.commerce.*BeanBase with the corresponding getter or setter method. Getters and setters for some foreign key fields are replaced by a getter/setter that gets/sets a parent or child JPA entity.
Note: If you added our own customizations to the JSP files that use EJB technology, we must migrate our customizations. Use the previous tables as a reference to help with the migration.
Previous topic: Migrate the WebSphere Commerce Search customizations.
Next topic: Migrate the Management Center.