سؤال

How do I know which attributes of an object were updated in a @PostUpdate event?

UPDATE - I've noticed that @PostUpdate is called right before the actual instant that the changes are committed, so if I access the DB using another datasource to the same database, I still can query it manually and check the changes by entity unique ID. Of course this can be a lot of work because an object is considered changed if one of its related objects is changed. What I'd like is something like this (http://docs.doctrine-project.org/en/2.0.x/reference/events.html#preupdate) but for openjpa. See the "PreUpdateEventArgs" concept.

UPDATE - also check openJPA proprietary @Auditable

هل كانت مفيدة؟

المحلول

A whole discussion about this feature is available here - http://openjpa.208410.n2.nabble.com/Audit-log-with-OpenJPA-tc6557932.html

Alternative solutions for these problem use respectively use PersistenceCapable (http://webspherepersistence.blogspot.com.br/2009/01/auditing-with-openjpa.html) and a ThreadLocal combined with @PreUpdate and @PostLoad (http://struberg.wordpress.com/2010/07/31/howto-changelog-with-jpa/)

As stated by @koitoer, JPA 2.1. does not have such a functionality, AFAHK.

Although, specifically for openJPA, it seems that there's a reasonable solution

http://openjpa.apache.org/builds/2.2.0/apache-openjpa/docs/ref_guide_audit.html

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top