EJB1.x entity callback method is not called with the correct state of the Entity in EAP6

Solution Verified - Updated

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6.x

Issue

  • If the container managed EJB 1.x Entity is loaded it is expected that the fields are loaded from the database with the current values. But all fields are not set!
  • There are SQL requests for each Entity attribute for a EJB2 Entity if attribute getters are accessed from the ejbLoad() method

Resolution

This is a problem in the container CMP engine tracked by This content is not included.BZ 1304458

Root Cause

According to the EJB3 specification chapter 11.1.4 the Entity fields must be loaded with the current values before the callback method ejbLoad() is called.

11.1.4 ejbLoad
When the container needs to synchronize the state of an enterprise bean instance with the entity object’s
state in the database, the container reads the entity object’s state from the database into the con-
tainer-managed fields and then it invokes the ejbLoad method on the instance.
The entity Bean Provider can rely on the container’s having loaded the container-managed fields from
the database just before the container invokes the ejbLoad method. The entity bean can use the ejb-
Load method, for instance, to perform some computation on the values of the fields that were read by
the container (for example, uncompressing text fields).

For EJB2 entities the attributes are lazy loaded if not already done because of the abstract getter methods. This is not the case for EJB1 entities.

Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.