On Oct 3, 2006, at 12:31 PM, Mike Kienenberger wrote:

1) These events are per-object and provide no reference to the current
persistent unit (DataContext).   Your entity instance might get events
from all persistent units committing a change.   You won't know what
persistent unit to append new audit log inserts.

True - in Cayenne you'd simply do [this|object].getObjectContext()... In JPA you'd have use threadlocals.

2) Because they are per-event, there is a much greater performance hit
-- several callbacks per entity instance.

Since you can register listeners for a single event type, this is not as bad as it looks (there won't be many noop calls).

If you need both old
values and new values, you will have to monitor both the pre- and
post- events.

True.

3) JPA states that no queries can be executed at this point.   So if
you want to create audit logs in the same transaction, you'll have to
figure out a way to delay those inserts until after the current commit
finishes but before the transaction commits.

In Cayenne I would still use a separate peer DataContext to commit changes from within callbacks. And use explicit transactions so that multiple DataContexts commit atomically.

4) JPA states that a new+update event and an update+delete event may
not execute the update event listener.

I used Cayenne callbacks on two different projects, and I actually find this behavior to be a good thing.

Andrus

Reply via email to