Migrate WebSphere Commerce Version 7 Feature Pack 8 EJB entity beans to Java Persistence API

Enterprise Java Entity Beans are no longer supported in WebSphere Commerce Version 9.0.0.1+. 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.0.0.1+ 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 7 development environment to the WebSphere Commerce Version 9.0.0.1+ development environment.


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:


Procedure

  1. 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.

      1. By using RAD, generate JPA entities from the database schema for the WebSphereCommerceServerExtensionsData project.

        1. Open Rational Application Developer.

        2. Right-click WebSphereCommerceServerExtensionsData, then click Rename.

        3. Back up the project by renaming it to something else, for example, WebSphereCommerceServerExtensionsData-EJB.

        4. Right-click the WC project, then click Properties > Deployment Assembly to change what is included in the Enterprise Archive (EAR).

        5. Click the WebSphereCommerceServerExtensionsData project that you renamed, for example, WebSphereCommerceServerExtensionsData-EJB. Then, click Remove > OK.

        6. Click File > New > JPA Project.

        7. For the project name, enter WebSphereCommerceServerExtensionsData.

        8. 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.

        9. Switch to your Data source Explorer.

        10. Right-click Database Connections, then click New.

        11. Select a database manager:

          • (DB2) For DB2 for Linux, UNIX, and Windows:

            1. Select JDBC driver IBM Data Server Driver for JDBC and SQLJ (JDBC 4.0) Default.

            2. Complete the fields for Database, Host, Port number, User name, Password, and Default schema.

            3. Click Finish.

          • (Oracle) For Oracle:

            1. Select JDBC driver Oracle 12 - Oracle Thin Driver Default.

            2. Click the ellipsis button (...) next to the JDBC driver, add or edit your JDBC driver, then click Ok.

            3. Fill out SID, Host, Port number, User name, Password, Default schema.

            4. Click Finish.

        12. Right-click the JPA project in the Project Explorer, then click JPA Tools > Generate Entities from Tables.

        13. On the Select tables page of the Generate Entities from Tables wizard, select the database connection createdd.

        14. Complete the wizard, then click Finish.

        15. Build your project by clicking Projects > Build All.

      2. Convert your EJB data beans to JPA data beans in the WebSphereCommerceServerExtensionsLogic project.

        1. Open a data bean class.

        2. Remove the references to the methods removed in the WebSphereCommerceServerExtensionsData project.

        3. 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

        4. 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

        5. Find all references to the setEJBRef(...) method and update the method name to setEntity.

        6. Find all references to .getEJBRef().remove() and update them to: .remove().

        7. Find all references to the getEJBRef() method and update the method name to getEntity.

        8. Repeat these substeps for all of your data bean classes.

      3. Convert your command classes to use JPA code in the WebSphereCommerceServerExtensionsLogic project.

        1. Open a command class.

        2. Remove the references to the methods removed in the WebSphereCommerceServerExtensionsData project.

        3. 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

        4. Update the logic to coincide with JPA.

        5. Repeat these substeps for every command class.

  2. 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 7.

      • javax.ejb.CreateException

      • javax.ejb.FinderException

      Where these exceptions were thrown by methods in WebSphere Commerce Version 7. Replace these by the appropriate javax.persistence.PersistenceException subclass.
      javax.ejb.DuplicateKeyException Where these exceptions were thrown by methods in WebSphere Commerce Version 7. 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.