Tutorials > Content management > Create a content-managed resource > Creating the new resource
Enable optimistic locking for the entity bean
Procedure
- Enable optimistic locking in the deployment descriptor:
- In the Enterprise Explorer view, navigate to WebSphereCommerceServerExtensionsData > Deployment Descriptor : WebSphereCommerceServerExtensionsData.
- Open the deployment descriptor for editing.
- In the Bean tab, select the ExtendedCatalogDescription.
- In the lower right pane, scroll down to the Concurrency Control section.
- Select Enable optimistic locking.
- Save the changes and close the EJB Deployment Descriptor editor.
- Set the optimistic predicate value of the optcounter field:
- In the Enterprise Explorer view, navigate to WebSphereCommerceServerExtensionsData > ejbModule > META-INF > backends > database_type, where database_type is the type of database you are using.
- Open the Map.mapxmi file for editing.
- In the Overview section, in the Enterprise Beans pane, select optcounter : short.
- Select the Properties view, and select true from the OptimisticPredicate list. Your screen should resemble the following screen capture:
![]()
- Edit methods to call optimistic locking classes. In the ExtendedCatalogDescriptionBean class make the following changes:
- In the Outline view, select ejbLoad() and add the following code as the first line in the method: super.ejbLoad();
- In the Outline view, select ejbStore() and add the following code as the first line in the method: super.ejbStore();
- In the Outline view, select ejbCreate(EntityBeanCreationData data) and add the following code:
The resulting method should look like the following snippet:
- Add this.initializeFields(); as the first line in the method.
- Add
ExtendedCatalogDescriptionKey myNewKey = new ExtendedCatalogDescriptionKey (catalog_id, language_id); this.initializeOptCounter(myNewKey);as the last two lines before the return statement.
public com.mycompany.catalog.objects.ExtendedCatalogDescriptionKey ejbCreate(EntityBeanCreationData data) throws javax.ejb.CreateException { this.initializeFields(); _initLinks(); ... ExtendedCatalogDescriptionKey myNewKey = new ExtendedCatalogDescriptionKey (catalogId, languageId); this.initializeOptCounter(myNewKey); return null; }
- Comment out the optCounter variable in the ExtendedCatalogDescriptionBean class.
Both the ECEntityBean and ExtendedCatalogDescriptionBean classes define a variable called optCounter, and each class maintains its own copy.
To ensure that both classes use the same optCounter variable, comment out the one defined in ExtendedCatalogDescriptionBean.
- Search for private short optCounter;; Comment out the variable as shown:
//private short optCounter;
- Save the changes.