All Examples  All EJB Examples

Packages examples.ejb.extensions.isModified and
examples.ejb.extensions.isModifiedBeanManaged

Enterprise JavaBean entity bean example packages and classes
demonstrating WebLogic's isModified extension

about these examples

These examples are two packages that demonstrate an Enterprise JavaBean. Please run these examples before attempting to create your own Enterprise JavaBeans, as they will show you the different steps involved. You should also have run our basic examples to gain an introduction to EJBeans.

The example is an entity EJBean called AccountBean that demonstrates using a WebLogic extension to EJB called isModified. The extension supplies the name of a method that's to be called and checked every time the bean is to be stored. Providing a method and setting it as appropriate will improve performance by eliminating unnecessary writing of the bean to the database.

The "unnecessary writing" comes about because normally the container -- when you're using container-managed persistence -- must write the contents of the bean after every invocation, as the container has no way of knowing that the bean's contents haven't been modified by the invocation. This WebLogic extension provides a mechanisim for telling the container when the bean has (and hasn't) been changed.

This optimization works by taking advantage of what we know about the logic of our business methods to reduce the number of times we go to the database to save the beans.

If your bean is such that there are no methods that don't change the value of the bean, and thus the container should save the contents after each invocation, then this technique is not appropriate. There are other circumstances (such as a shared databases) where you should not use this technique.

The example demonstrates:

The Client applications perform these steps:
  1. Part A
    1. Contacts the Account home through JNDI to find an EJBean
    2. Searches for a specific Account ('10020'), and creates it if it can't be found
    3. Deposits an amount
    4. Gets the balance
    5. Withdraws the same amount
    6. Gets the balance
  2. Part B
    1. Use the containerManaged example EJBean
    2. Contacts the containerManaged Account home through JNDI to find an EJBean
    3. Searches for a specific Account ('10020'), and creates it if it can't be found
    4. Deposits an amount
    5. Gets the balance
    6. Withdraws the same amount
    7. Gets the balance

Using this feature will not remove your EJBeans' portability, as you are simply adding two methods and a transient value that other containers will ignore.

This is an advanced usage of Enterprise JavaBeans, and it's easy to make a mistake with it. It should only be used by developers who have an in-depth understanding of EJB and databases.

Container-managed persistence and isModified

To enable the extension, specify a method name in the deployment descriptor for the isModifiedMethodName property, as shown in the container-managed DeploymentDescriptor.txt:
  isModifiedMethodName          isModified