persistence@glassfish.java.net

Determine whether entity was changed

From: msmolyak <msmolyak_at_rocketmail.com>
Date: Fri, 10 Oct 2008 11:58:38 -0700 (PDT)

Hello,

I am writing a Spring MVC/EJB 3 application using JPA with TopLink
Essentials. The application is deployed on Oracle AS 10.3.

The entities in the application have persistent audit fields to keep track
of who changed the entity and when. The audit fields are populated using EJB
3 interceptor mechanism. Each time a create or update is called on the
Session Facade for an entity, the interceptor populates the audit fields,
after which the entity is persisted.

The problem with this approach is that the audit fields are updated
regardless of whether the entity was actually updated or not. As long as
update() was invoked (even if no field has changed its value) the audit
fields will be updated and the TopLink will be forced to update the
corresponding database table.

I know that TopLink uses UnitOfWork mechanism to maintain the list of
entities updated for the given transaction. Through it, TopLink knows which
entities require writing to the database. My question is whether it is
possible for my code in the audit field updating logic to determine whether
the entity being processed has been changed. I understand that I can track
the changes myself using a dirty flag, but I am trying to avoid it.

How can I access the TopLink API and determine for the given entity (for
which update() was called) whether it needs updating in the database?

Thank you,

Michael
-- 
View this message in context: http://www.nabble.com/Determine-whether-entity-was-changed-tp19924098p19924098.html
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.