users@glassfish.java.net

Re: EJBContext: thread safe?

From: Laird Nelson <ljnelson_at_gmail.com>
Date: Fri, 19 Aug 2011 10:45:05 -0400

On Fri, Aug 19, 2011 at 10:31 AM, Laird Nelson <ljnelson_at_gmail.com> wrote:

> So here's (part of the monstrous) stack I get in the logger's warning above
> (again, apologies to forum readers for the hatchet job on the formatting the
> forum software will perform):
>

Actually, another thing that is slightly alarming is that the
@PreUpdate callback
is being fired on a simple "find" method (i.e. no
EntityManager.merge()call). That seems to be because a
@PreUpdate call can happen when an entity's state is flushed to the database
(i.e. whether you merge() it or not). Thus speaketh the JPA specification
(3.5.2):

The PreUpdate and PostUpdate callbacks occur before and after the database
> update operations to entity data respectively. These database operations may
> occur at the time the entity state is updated or they may occur at the time
> state is flushed to the database (which may be at the end of the
> transaction).
>

  That means my entity listener can be invoked on every single simple
findByPrimaryKey() operation (i.e. when the entity has actually NOT been
updated). That seems wrong--is there some obvious way I can detect whether
my entity listener invocation is due to a simple database flush versus an
actual update? Or is the fact that its state is being flushed to the
database on a simple find operation a problem (it sure looks to ME like it
is)?

So many questions. :-)

Best,
Laird

-- 
http://about.me/lairdnelson