You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Julien Kronegg (JIRA)" <ji...@apache.org> on 2009/04/02 16:41:13 UTC
[jira] Updated: (OPENJPA-1018) @PreUpdate raised for new entities
annotated with @EntityListeners
[ https://issues.apache.org/jira/browse/OPENJPA-1018?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Julien Kronegg updated OPENJPA-1018:
------------------------------------
Description:
Given the following entity:
@Entity
@EntityListeners({Auditing.class})
@Table(...)
public class A {
...
}
and the following Auditing class:
public class Auditing {
@PreUpdate
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())
fireLifecycleEvent(LifecycleEvent.BEFORE_DELETE);
else if (!(isNew() && !isFlushed())
&& (ImplHelper.getUpdateFields(this) != null))
fireLifecycleEvent(LifecycleEvent.BEFORE_UPDATE);
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 (supposed to be a boolean table):
isNew
true.....false
isFlushed true...................fire
false.................fire
which gives:
else if (!isNew() && (ImplHelper.getUpdateFields(this) != null))
was:
Given the following entity:
@Entity
@EntityListeners({Auditing.class})
@Table(...)
public class A {
...
}
and the following Auditing class:
public class Auditing {
@PreUpdate
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())
fireLifecycleEvent(LifecycleEvent.BEFORE_DELETE);
else if (!(isNew() && !isFlushed())
&& (ImplHelper.getUpdateFields(this) != null))
fireLifecycleEvent(LifecycleEvent.BEFORE_UPDATE);
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:
isNew
true false
isFlushed true fire
false fire
which gives:
else if (!isNew() && (ImplHelper.getUpdateFields(this) != null))
tried to make the boolean table more readable
> @PreUpdate raised for new entities annotated with @EntityListeners
> ------------------------------------------------------------------
>
> Key: OPENJPA-1018
> URL: https://issues.apache.org/jira/browse/OPENJPA-1018
> Project: OpenJPA
> Issue Type: Bug
> Components: kernel
> Affects Versions: 1.2.0, 1.2.1, 1.3.0, 2.0.0
> Environment: http://fisheye6.atlassian.com/browse/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java?r=761031
> Reporter: Julien Kronegg
> Original Estimate: 4h
> Remaining Estimate: 4h
>
> Given the following entity:
> @Entity
> @EntityListeners({Auditing.class})
> @Table(...)
> public class A {
> ...
> }
> and the following Auditing class:
> public class Auditing {
> @PreUpdate
> 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())
> fireLifecycleEvent(LifecycleEvent.BEFORE_DELETE);
> else if (!(isNew() && !isFlushed())
> && (ImplHelper.getUpdateFields(this) != null))
> fireLifecycleEvent(LifecycleEvent.BEFORE_UPDATE);
> 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 (supposed to be a boolean table):
> isNew
> 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.