Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Inheriting Lifecycle Callback Methods Not Working as Expected

I have an abstract class AbstractBaseEntity responsible for maintaining a
surrogate UID key used to provide hashcode and equals implementations for
entity subclasses.  
The class is annotated with @MappedSuperclass 

The base entity has @PrePersist and @PostLoad callbacks used to broker the
UID object to and from a String stored in the database

Next I have an entity class FamilyCard that extends the AbstractBaseEntity
class.  The FamilyCard class has a @PrePersist callback used to set the date
when the entity is persisted.

When I try to build and deploy then I am getting the following exception
complaining of multiple lifecycle callback methods.

Exception Description: Deployment of PersistenceUnit [CCMS-Domain] failed.
Internal Exception: Exception [EclipseLink-7227] (Eclipse Persistence
Services - 2.1.2.v20101206-r8635):
org.eclipse.persistence.exceptions.ValidationException
Exception Description: The listener class [class
uk.gov.sunderland.ccms.model.entity.FamilyCard] has multiple lifecycle
callback methods for the same lifecycle event ([private void
uk.gov.sunderland.ccms.model.entity.AbstractBaseEntity.createUIdStr()] and
[private void
uk.gov.sunderland.ccms.model.entity.FamilyCard.setCreatedDate()]). 

This is not the expected behaviour.  I was expecting the AbstractBaseEntity
callbacks to be called first then the callback in the FamilyCard entity.

In the Pro JPA 2 book by Mike Keith it says :

Callback methods may occur on any entity or mapped superclass, be it
abstract or concrete. The rule is 
fairly simple. It is that every callback method for a given event type will
be invoked in the order 
according to its place in the hierarchy, most general classes first. Thus,
if in our Employee hierarchy that 
we saw in Figure 10-10 the Employee class contains a PrePersist callback
method named checkName(), 
and FullTimeEmployee also contains a PrePersist callback method named
verifyPension(), when the 
PrePersist event occurs, the checkName() method will get invoked, followed
by the verifyPension() 
method.


Any guidance really appreciated.  
 
http://old.nabble.com/file/p30613316/AbstractBaseEntity.java
AbstractBaseEntity.java 
http://old.nabble.com/file/p30613316/FamilyCard.java FamilyCard.java 
-- 
View this message in context: http://old.nabble.com/Inheriting-Lifecycle-Callback-Methods-Not-Working-as-Expected-tp30613316p30613316.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top