If the Entities in your persistence context (EM) have not been modified, but
preUpdate is being called for them, then this sounds like a bug.  The
preUpdate should only be called for Entities that have actually been
updated.  And, it makes sense that if you close/clear the EM before doing
the merge(), then the only Entity in your EM is the one being modified.

What version of OpenJPA are you using?  We did make a change in this area
due to the JPA 2.0 spec so that certain callback methods would not be called
between the persist and commit methods [1].  But, your situation sounds
different from that.

[1]
http://openjpa.apache.org/builds/2.0.0/apache-openjpa-2.0.0/docs/manual/manual.html#prePostUpdate

On Wed, May 19, 2010 at 10:40 AM, C N Davies <[email protected]> wrote:

> My code loads a collection of entities using findall(class). The em is left
> open rather than having to open and close it every time the user performs
> an
> operation on one of these objects in the list.
>
>
>
> Below is my PreUpdate listener for that entity, so I know when it is
> getting
> called I have system.out right now.
>
>
>
> The problem is that if I use em.merge(entity)   the PreUpdate listener will
> be called on each one of the entities in the list not only the entity I am
> merging. If I close the em and create a new one then call em.merge(entity),
> the PreUpdate listener will only be called on the entity I am merging.
>
>
>
>      @PreUpdate
>
>      public void update(){
>
>            System.out.println("Running preupdate dataload listener");
>
>            this.updateCounters();
>
>      }
>
>
>
> I expected this would be due to runtime enhanced classes so didn't pay much
> attention to it, but now I  have being using it after build time enhancing
> my classes I have the same issue. It seems like it wants to run the
> PreUpdate listener on anything of this entity class that is attached to the
> current em.
>
>
>
> Have anyone seen this before?
>
>
>
> Chris
>
>
>
>

Reply via email to