|
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g Release 3 (10.1.3) B14428-01 |
|
![]() Previous |
![]() Next |
You can specify an EJB 3.0 entity class method as a callback method for any of the following lifecycle events:
Pre-persist: a method called on an object when that object has the create operation applied to it.
Post-persist: a method called on an object that has just been inserted into the database. You can use this method to notify any of the object's dependents or to update information not accessible until the object has been inserted.
Pre-remove: a method called on an object when that object has the remove operation applied to it.
Post-remove: a method called on an object that has just been deleted from the database. You can use this method to notify or remove any of the object's dependents.
Pre-update: a method called when an object's row is about to be updated.
The TopLink persistence manager calls this method only if it determines that an actual update is required (only if it is prepared to send SQL to the database). Contrast this with a post-update callback which is called whether or not an actual change was required.
You can use this method to modify the row before insert.
Post-update: a method called on an object that has just been updated into the database.
Use this callback to update any dependent objects.
The TopLink persistence manager calls this method even if it determines that no actual update is required (even if it determines that no SQL needs to be sent to the database). Use the pre-update callback if you want to be notified only when the object has actually been changed.
Post-load: a method called on an object that has just been built from the database. This event can be used to correctly initialize an object's non-persistent attributes or to perform complex optimizations or mappings. This event is called whenever an object is built.
The entity class method must have the following signature:
public int <MethodName>()
For more information, see:
"Descriptor Event Manager" in the Oracle TopLink Developer's Guide
"Configuring a Domain Object Method as an Event Handler" in the Oracle TopLink Developer's Guide
|
Note: For an EJB 3.0 lifecycle callback method code example, see:http://www.oracle.com/technology/tech/java/oc4j/ejb3/howtos-ejb3/howtoejb30mappingannotations/doc/how-to-ejb30-mapping-annotations.html#callbacks.
|
You can specify an EJB 3.0 entity class method as a lifecycle callback method using any of the following annotations:
Example 7-25 shows how to use the @PrePersist annotation to specify EJB 3.0 entity class method initialize as a lifecycle callback method.