Creating new entity beans
When you have a new attribute that needs to be added to the WebSphere Commerce object model, you can create a new database table with a column for the required attribute. You must then also include this attribute in an enterprise bean, so that WebSphere Commerce commands can access the information. One way to integrate the new attribute into the WebSphere Commerce object model is to create a new CMP enterprise bean. In this bean, you create a field that corresponds to the attribute in the new database table. Since WebSphere Commerce workspace provides a predefined EJB project for your new enterprise beans, you do not need to create an additional EJB project. Your new enterprise beans should be placed into the WebSphereCommerceServerExtensionsData EJB project. Later, when you deploy your customized beans, you create a WebSphereCommerceServerExtensionsData.jar JAR file and replace the existing JAR file in the WebSphere Commerce enterprise application running in WebSphere Application Server. By using this packaging convention, deployment is greatly simplified.
The following enterprise bean coding practices should be observed:
- Enterprise bean code should not reference anything outside of the enterprise bean modules. For example, you should not reference commands or data beans in the enterprise bean code.
- The previous sections describe how to include access control in a new bean when initially creating the bean. It can also be added after you have created your bean by adding the com.ibm.commerce.security.Protectable interface. If required, also add the com.ibm.commerce.security.Groupable interface to the enterprise bean's remote interface. Certain methods must be implemented in the bean as well. After adding these interfaces and adding required methods, regenerate the bean's deployed code and access bean. For more information, see Protectable interface.
- The instructions to create a new CMP enterprise
bean below include sections to enable optimistic locking. The sections
are:
- Creating an optcounter column in your table and an optcounter field in your entity bean in step 1.
- Ensuring the isolation level for the entity bean is Read Committed in step 2.
- Selecting the optimistic locking option in the entity bean's deployment descriptor in step 5.
- Calling super.ejbLoad and super.ejbStore methods in step 7.
- Ensuring any finder methods that use a
FOR UPDATE
clause also include theWITH RS
clause in step 8. - Initializing the optcounter field in the ejbCreate method in step 10.
If needed, you can use the optimistic locking migration plug-in to enable optimistic locking in your new entity bean instead of performing the sections listed above. Use the optimistic locking migration plug-in after generating the access bean and before generating deploy code.