You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by C N Davies <cn...@cndavies.com> on 2010/05/19 17:40:30 UTC

PreUpdate listener is very nosey!

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

 


RE: PreUpdate listener is very nosey!

Posted by C N Davies <cn...@cndavies.com>.
Only the single entity will have been modified,  I was expecting as you say
that only modified entities would be running PreUpdate. I'm using OpenJPA
2.0.0 GA.

 

 Looked at 1.3.2.  PreUpdate/PostUpdate Life Cycle Callbacks   but since
these entities have not be touched in anyway other then to retrieve them, I
don't' thin it is relevant.

 

 

 

Chris

 

 

 

From: Kevin Sutter [mailto:kwsutter@gmail.com] 
Sent: Thursday, 20 May 2010 1:55 AM
To: users@openjpa.apache.org; cnd@cndavies.com
Subject: Re: PreUpdate listener is very nosey!

 

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/manu
al.html#prePostUpdate

On Wed, May 19, 2010 at 10:40 AM, C N Davies <cn...@cndavies.com> 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




 


Re: PreUpdate listener is very nosey!

Posted by Kevin Sutter <kw...@gmail.com>.
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 <cn...@cndavies.com> 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
>
>
>
>