Community
Participate
Working Groups
If I create an @Entity inherited from a @MappedSuperclass and both of them have independent (no method overriding) but the same lifecycle callback method, for example @PrePersist, the following exception occur. Internal Exception: Exception [EclipseLink-7227] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.ValidationException Exception Description: The listener class [class my.MyEntity] has multiple lifecycle callback methods for the same lifecycle event ([private void my.MyMappedSuperclass.myMappedSuperclassPrePersist()] and [private void my.MyEntity.myEntityPrePersist()]). at org.eclipse.persistence.exceptions.EntityManagerSetupException.deployFailed(EntityManagerSetupException.java:218) ... 61 more Caused by: Exception [EclipseLink-7227] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.ValidationException Exception Description: The listener class [class my.MyEntity] has multiple lifecycle callback methods for the same lifecycle event ([private void my.MyMappedSuperclass.myMappedSuperclassPrePersist()] and [private void my.MyEntity.myEntityPrePersist()]). at org.eclipse.persistence.exceptions.ValidationException.multipleLifecycleCallbackMethodsForSameLifecycleEvent(ValidationException.java:2246) at org.eclipse.persistence.internal.jpa.metadata.listeners.EntityListener.addEventMethod(EntityListener.java:120) at org.eclipse.persistence.internal.jpa.metadata.listeners.EntityClassListener.addEventMethod(EntityClassListener.java:46) at org.eclipse.persistence.internal.jpa.metadata.listeners.EntityListener.setPrePersistMethod(EntityListener.java:462) at org.eclipse.persistence.internal.jpa.metadata.listeners.EntityListenerMetadata.setPrePersist(EntityListenerMetadata.java:475) at org.eclipse.persistence.internal.jpa.metadata.listeners.EntityListenerMetadata.processCallbackMethods(EntityListenerMetadata.java:383) at org.eclipse.persistence.internal.jpa.metadata.listeners.EntityClassListenerMetadata.process(EntityClassListenerMetadata.java:74) at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.processListeners(EntityAccessor.java:1068) at org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.addEntityListeners(MetadataProcessor.java:104) at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:327) According to the JPA specifications 1.0 and 2.0, this is a legitimate use case (2.11.2 Mapped Superclasses) and the behavior of multiple lifecycle callback methods is also specified. (3.5.4 Multiple Lifecycle Callback Methods for an Entity Lifecycle Event) My test classes to reproduce this bug. === CUT === package my; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.MappedSuperclass; import javax.persistence.PrePersist; @MappedSuperclass public abstract class MyMappedSuperclass { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; private String createdBy; @PrePersist private void myMappedSuperclassPrePersist() { if (createdBy == null) { createdBy = "root"; } } } === CUT === package my; import javax.persistence.Entity; import javax.persistence.PrePersist; @Entity public class MyEntity extends MyMappedSuperclass { private String data; @PrePersist private void myEntityPrePersist() { if (data == null) { data = "NO DATA"; } } } === CUT ===
Setting target and priority. See the following page for details of what these values mean. http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
Created attachment 174415 [details] Proposed changes Change includes some clean up to the jpa.xml.merge.advanced test model.
Changes have been submitted. Reviewed by: Michael O'Brien Tests: New test (testPreAndPostPersistExpertBeerConsumer) was added to the InheritedCallbacksJunitTest includes model changes to the inherited model. Patch also includes some clean up to the xml.merge.advanced model.
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink