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

You created all necessary ejbCreate methods.

Procedure

  1. In the Project Explorer view, double-click the YourNewBeanBean class to open it and view its source code.
  2. For each ejbCreate method in the class:
  3. Add this.initializeFields(); as the first line in the method.
  4. 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; }
  5. Proceed to creating a new ejbPostCreate method.