openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Julien Kronegg (JIRA)" <>
Subject [jira] Created: (OPENJPA-1018) @PreUpdate raised for new entities annotated with @EntityListeners
Date Thu, 02 Apr 2009 14:37:12 GMT
@PreUpdate raised for new entities annotated with @EntityListeners

                 Key: OPENJPA-1018
             Project: OpenJPA
          Issue Type: Bug
          Components: kernel
    Affects Versions: 1.2.1, 1.2.0, 1.3.0, 2.0.0
            Reporter: Julien Kronegg

Given the following entity:

    public class A {

and the following Auditing class:

    public class Auditing {
      public void preUpdate(Object entity) { // the provided object is supposed to be a PersistenceCapable

When using runtime enhancement, the PreUpdate event is raised and preUpdate(Object) is called
when persisting a new entity: the call is not expected as the entity is not yet persisted
(moreover, the entity passed in parameter is not an instance of PersistenceCapable). 

This is due to StateManagerImpl.preFlush() lifecycle event firing conditions: 

            // BEFORE_PERSIST is handled during Broker.persist and Broker.attach
            if (isDeleted())
             else if (!(isNew() && !isFlushed())
                                 && (ImplHelper.getUpdateFields(this) != null))

When processing a PNewState, the condition for BEFORE_UPDATE event becomes simply: isFlushed().
The correct full condition would include a condition to prevent raising BEFORE_UPDATE for
new entities:

                                          true    false
    isFlushed       true                   fire
                             false                 fire

which gives:     

      else if (!isNew() && (ImplHelper.getUpdateFields(this) != null))

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message