Can I by only using JPA somehow keep track of a whole Entity-Graphs state?
Consider having a Hierarchy with two or three classes in them with at least one Collection.
By using JPA @Post... Annotations I can only keep track of the actual entity and not its children and or Collections as it is pretty much just the Data-Base Event wrapped.
I know Hibernate can do that, but I don't want to rely on the implementation of the JPA for doing this.
I would be pretty happy if there was a way to do this with EclipseLink at least.
Not sure if this is what you're searching for, but you can detect change on your entities like so:
Account a = em.merge(account);
final JpaEntityManager jpaEntityManager = (JpaEntityManager) em.getDelegate();
final UnitOfWorkChangeSet changeSet = jpaEntityManager.getUnitOfWork().getCurrentChanges();
final ObjectChangeSet accountChangeSet = changeSet.getObjectChangeSetForClone(a);
final ObjectChangeSet userChangeSet = changeSet.getObjectChangeSetForClone(a.getUser());
em.clear();
//checks only for these 2 specific fields; changeSet.hasChanges() would check for all changes
return accountChangeSet.hasChangeFor("credits") || userChangeSet.hasChangeFor("name");
Hope this somewhat helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With