Skip to main content

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

I've followed youre advice on the @EntityListener route as I don't want an
extra table created.  It works just great.
http://old.nabble.com/file/p30615252/AbstractBaseEntityListener.java
AbstractBaseEntityListener.java 

Many Thanks

Magnus


Guy Pelletier wrote:
> 
>   The difference here is your MappedSuperclass, Mike's example uses an 
> entity hierarchy.
> 
> By using the MappedSuperclass as the parent you are essentially saying 
> FamilyCard has two pre persists methods which is not allowed. You should 
> be ok if you change AbstractBaseEntity to be an @Entity or use an 
> @EntityListener class on the mapped superclass.
> 
> Cheers,
> Guy
> 
> 
> On 07/01/2011 6:59 AM, magnus2025 wrote:
>> 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
> 
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
> 
> 

-- 
View this message in context: http://old.nabble.com/Inheriting-Lifecycle-Callback-Methods-Not-Working-as-Expected-tp30613316p30615252.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top