9.3. isModified Optimization for Container-managed Entity Beans

To improve performance, JOnAS implements the isModified extension. Before performing an update, the container calls a method of the bean whose name is identified in the is-modified-method-name element of the JOnAS-specific deployment descriptor. This method is responsible for determining if the state of the bean has been changed. By doing this, the container determines if it must store data in the database or not.

9.3.1. isModified Example

The bean implementation manages a boolean isDirty and implements a method that returns the value of this boolean: isModified

private transient boolean isDirty;
public boolean isModified() {
    return isDirty;
}

The JOnAS-specific deployment descriptor directs the bean to implement an isModified method:

<jonas-entity>
  <ejb-name>Item</ejb-name>
  <is-modified-method-name>isModified</is-modified-method-name>
  .....
</jonas-entity>

Methods that modify the value of the bean must set the flag isDirty to true. Methods that restore the value of the bean from the database must reset the flag isDirty to false. Therefore, the flag must be set to false in the ejbLoad() and ejbStore() methods.