Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 348361

Summary: Event definitions (pre-persist, pre-update ..) are ignored when defined in <mapped-superclass>
Product: z_Archived Reporter: CorForLive <corforlive>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3 CC: eclipselink.orm-inbox, guy.pelletier
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Proposed changes none

Description CorForLive CLA 2011-06-06 04:27:10 EDT
Build Identifier: 

Situation:
- The whole domain model is defined in the orm.xml file. All entities are simple POJOs (no jpa annotations are used at all). 
- All entities extend a base entity declared in the orm.xml using <mapped-superclass ..> 

Problem:
Adding event declarations (pre-persist, pre-update ..) into orm.xml to the mapped-superclass does not bring any effect. These declarations seem to be ignored. Example:

public abstract class BaseEntity {

  private Timestamp insertTimestamp;
  private Timestamp lastUpdateTimestamp;

  public void onPersist() {
    ...   
  }

  public void onUpdate() {
    ...
  }
}

<mapped-superclass class="com.my.model.BaseEntity">
   <pre-persist method-name="onPersist"/>
   <pre-update method-name="onUpdate"/>
   <post-load method-name="postLoad"/>
</mapped-superclass> 

Replacing the xml definitions with annotations (@PreUpdate, @PrePersist, ..) directly in the BaseEntity class solves the problem. Also moving the xml declarations from the superclass to the subclass solved the problem.

It look like the bug while the parsing/mapping the <mapped-superclass> XML declaration. Event declarations seem to be ignored / don't work. The annotation-based equivalent seems to work correctly.

I'm using EclipseLink 2.2.0 with H2 in the SE environment developing under MacOs+IntelliJ

Reproducible: Always

Steps to Reproduce:
1. Create an entity class and declare as entity using orm.xml
2. Create a superclass for the created entity class and declare in orm.xml using <mapped-superclass>
3. Add <pre-persist> and/or <pre-update> to the superclass in the orm.xml
4. Persist and/or update the entity and check wether the events method in the base class are being called.
Comment 1 Guy Pelletier CLA 2011-06-09 14:33:21 EDT
Created attachment 197719 [details]
Proposed changes
Comment 2 Guy Pelletier CLA 2011-06-09 14:57:32 EDT
Changes submitted.

Verified by: Tom Ware

Tests: Modified existing test (testCreateBeerConsumer) from EntityMappingsInheritedJUnitTestCase.
Comment 3 Eclipse Webmaster CLA 2022-06-09 10:19:07 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink