java - How would I audit the changes to a list of JPA entities? -


i've got 2 lists of entities: 1 current state of rows in db, other changes made list. how audit rows deleted, added, , changes made entities? audit table used entities.

entity listeners , callback methods perfect fit, until notice sentence says: a callback method must not invoke entitymanager or query methods! because of restriction, can collect audits, can't persist them database :(

my solution has been complex algorithm discover audits.

if entity in change list , has no key, it's add  if entity in db not changes list, it's delete  if entity in both list, recursively compare fields find differences audit (if any) 

i collect these , insert them db in same transaction merge changes list. hate fact i'm writing hand. seems jpa should able logic me.

one solution we've come use entity listener posts audits jms queue. queue inserts audits database. don't solution because think setting jms queue pain. it's best solution we've got though.


i'm using eclipselink (ideally, that's not relevant) , have found these 2 things helpful jms queue better solution them:

the entitylistener looks approach since able collect audit information.

have tried persisting information in different transaction 1 persisting changes? perhaps obtaining reference stateless ejb (assuming using ejbs) , using methods marked @transactionattribute(transactionattributetype.requires_new). in way transaction persisting original changes put on hold while transaction of audit completes. note not able access updated information in separate audit transaction, since original 1 has not committed yet.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -