You can write EntityListeners based on your requirements. Several example scripts follow.
@Entity
@EntityListeners({EmployeeListener.class, EmployeeListener2.class})
public class Employee {
@PrePersist
public void checkEmployeeID() {
....
}
}
public class EmployeeListener {
@PrePersist
public void onEmployeePrePersist(Employee e) {
....
}
}
public class PersonListener {
@PrePersist
public void onPersonPrePersist(Object person) {
....
}
}
public class EmployeeListener2 extends PersonListener {
@PrePersist
public void onEmployeePrePersist2(Object employee) {
....
}
}
<entity
class-name="com.ibm.websphere.objectgrid.sample.Employee"
name="Employee" access="FIELD">
<attributes>
<id name="id" />
<basic name="value" />
</attributes>
<entity-listeners>
<entity-listener
class-name="com.ibm.websphere.objectgrid.sample.EmployeeListener">
<pre-persist method-name="onListenerPrePersist" />
<post-persist method-name="onListenerPostPersist" />
</entity-listener>
</entity-listeners>
<pre-persist method-name="checkEmployeeID" />
</entity>
The entity Employee is configured with a com.ibm.websphere.objectgrid.sample.EmployeeListener entity
listener class , which has two life-cycle callback methods defined.
The onListenerPrePersist method is for the PrePersist
event, and the onListenerPostPersist method is
for the PostPersist event. Also, the checkEmployeeID method
in the Employee class is configured to listen for the PrePersist event.