Initialize optimistic locking fields in ejbCreate
To take advantage of optimistic locking, you must initialize the optCounter field in your entity bean in the ejbCreate method.
Before you begin
Procedure
- In the Project Explorer view, double-click the YourNewBeanBean class to open it and view its source code.
- For each ejbCreate method in the class:
- Add this.initializeFields(); as the first line in the method.
- Add this.initializeOptCounter( primaryKey); as
the last line in the method before the return statement, where primaryKey is
the key generated by the key class. This method must be called after the primary
key is set.
The resulting method should look similar to the following example, in which memberId is the primary key:
public com.ibm.commerce.extension.objects.BonusKey ejbCreate( java.lang.Long memberId,java.lang.Integer bonusPoint) throws javax.ejb.CreateException { this.initializeFields(); _initLinks(); this.memberId=memberId; this.bonusPoint=bonusPoint; BonusKey myNewBonusKey = new BonusKey (memberId); this.initializeOptCounter(myNewBonusKey); return null; }
- Proceed to creating a new ejbPostCreate method.