java - Envers throws RuntimeException in ValidityAuditStrategy when no audit records (table partitioning) -
in envers (persistence.xml), enabled strategy table partitioning, according development guide: http://docs.jboss.org/hibernate/orm/4.2/devguide/en-us/html/ch15.html#envers-partitioning
the class: validityauditstrategy, throws runtimeexception when there no audit record. exception occurs when envers try update audit record date of final revision (revend_tstmp), audit record not exist.
the database of application receives data load external applications , not possible change these external applications include audit records.
i have no chance handle exception (i don't know how).
in method validityauditstrategy#updatelastrevision:
if (l.size() == 1) { //... dostuff - ok } else { throw new runtimeexception("cannot find previous revision entity " + auditedentityname + " , id " + id); } in method validityauditstrategy#perform:
if ( rowcount != 1 ) throw new runtimeexception("cannot update previous revision entity " + auditedentityname + " , id " + id); a similar issue occurred in link: https://developer.jboss.org/thread/160195?tstart=0 had no solution.
it's possible apply workaround?
i use hibernate-envers-4.1.3-final version.
log:
2015-07-17 10:23:28,653 debug [-] [org.hibernate.sql] (http-/0.0.0.0:8080-5) update my_entity_aud set id_rev_final=?, date_hour_rev_final=? id_entity=? , id_rev <> ? , id_rev_final null 2015-07-17 10:23:28,677 trace [-] [org.hibernate.type.descriptor.sql.basicbinder] (http-/0.0.0.0:8080-5) binding parameter [1] [integer] - 422 2015-07-17 10:23:28,677 trace [-] [org.hibernate.type.descriptor.sql.basicbinder] (http-/0.0.0.0:8080-5) binding parameter [2] [timestamp] - thu jul 17 10:23:28 brt 2015 2015-07-17 10:23:28,677 trace [-] [org.hibernate.type.descriptor.sql.basicbinder] (http-/0.0.0.0:8080-5) binding parameter [3] [integer] - 12345 2015-07-17 10:23:28,678 trace [-] [org.hibernate.type.descriptor.sql.basicbinder] (http-/0.0.0.0:8080-5) binding parameter [4] [integer] - 422 2015-07-17 10:23:28,803 error [-] [org.hibernate.assertionfailure] (http-/0.0.0.0:8080-5) hhh000099: assertion failure occured (this may indicate bug in hibernate, more due unsafe use of session): java.lang.runtimeexception: cannot update previous revision entity my.package.myentity_aud , id 12345 2015-07-17 10:23:28,841 warn [-] [com.arjuna.ats.arjuna] (http-/0.0.0.0:8080-5) arjuna012125: twophasecoordinator.beforecompletion - failed synchronizationimple< 0:ffffac1c045d:-3a5600e4:55a7c120:131, org.hibernate.engine.transaction.synchronization.internal.registeredsynchronization@5619c5a3 >: org.hibernate.assertionfailure: unable perform beforetransactioncompletion callback @ org.hibernate.engine.spi.actionqueue$beforetransactioncompletionprocessqueue.beforetransactioncompletion(actionqueue.java:754) [hibernate-core-4.1.3-final.jar:4.1.3-final] @ org.hibernate.engine.spi.actionqueue.beforetransactioncompletion(actionqueue.java:338) [hibernate-core-4.1.3-final.jar:4.1.3-final] @ org.hibernate.internal.sessionimpl.beforetransactioncompletion(sessionimpl.java:490) [hibernate-core-4.1.3-final.jar:4.1.3-final] @ org.hibernate.engine.transaction.synchronization.internal.synchronizationcallbackcoordinatornontrackingimpl.beforecompletion(synchronizationcallbackcoordinatornontrackingimpl.java:114) [hibernate-core-4.1.3-final.jar:4.1.3-final] @ org.hibernate.engine.transaction.synchronization.internal.registeredsynchronization.beforecompletion(registeredsynchronization.java:53) [hibernate-core-4.1.3-final.jar:4.1.3-final] @ com.arjuna.ats.internal.jta.resources.arjunacore.synchronizationimple.beforecompletion(synchronizationimple.java:76) @ com.arjuna.ats.arjuna.coordinator.twophasecoordinator.beforecompletion(twophasecoordinator.java:273) @ com.arjuna.ats.arjuna.coordinator.twophasecoordinator.end(twophasecoordinator.java:93) @ com.arjuna.ats.arjuna.atomicaction.commit(atomicaction.java:162) @ com.arjuna.ats.internal.jta.transaction.arjunacore.transactionimple.commitanddisassociate(transactionimple.java:1189) @ com.arjuna.ats.internal.jta.transaction.arjunacore.basetransaction.commit(basetransaction.java:126) @ com.arjuna.ats.jbossatx.basetransactionmanagerdelegate.commit(basetransactionmanagerdelegate.java:75) @ org.jboss.as.ejb3.tx.cmttxinterceptor.endtransaction(cmttxinterceptor.java:92) [jboss-as-ejb3-7.4.0.final-redhat-19.jar:7.4.0.final-redhat-19] ... caused by: java.lang.runtimeexception: cannot update previous revision entity entity my.package.myentity_aud , id 12345 @ org.hibernate.envers.strategy.validityauditstrategy.perform(validityauditstrategy.java:210) [hibernate-core-4.1.3-final.jar:4.1.3-final] @ org.hibernate.envers.synchronization.work.abstractauditworkunit.perform(abstractauditworkunit.java:76) [hibernate-core-4.1.3-final.jar:4.1.3-final] @ org.hibernate.envers.synchronization.auditprocess.executeinsession(auditprocess.java:116) [hibernate-core-4.1.3-final.jar:4.1.3-final] @ org.hibernate.envers.synchronization.auditprocess.dobeforetransactioncompletion(auditprocess.java:155) [hibernate-core-4.1.3-final.jar:4.1.3-final] @ org.hibernate.envers.synchronization.auditprocessmanager$1.dobeforetransactioncompletion(auditprocessmanager.java:62) [hibernate-core-4.1.3-final.jar:4.1.3-final] @ org.hibernate.engine.spi.actionqueue$beforetransactioncompletionprocessqueue.beforetransactioncompletion(actionqueue.java:748) [hibernate-core-4.1.3-final.jar:4.1.3-final] ... 90 more
in persistence.xml existing property specify custom auditstrategey: org.hibernate.envers.audit_strategy. change, from:
<property name="org.hibernate.envers.audit_strategy" value="org.hibernate.envers.strategy.validityauditstrategy"/> to:
<property name="org.hibernate.envers.audit_strategy" value="com.app.your.pack.yourcustomvalidityauditstrategy"/> so can extend validityauditstrategy , override perform() not throw runtimeexception when there no previous revision entity, this:
public class yourcustomvalidityauditstrategy extends validityauditstrategy { private final log logger = logfactory.getlog(getclass()); @override public void perform(session session, string entityname, auditconfiguration auditcfg, serializable id, object data, object revision) { try { super.perform(session, entityname, auditcfg, id, data, revision); } catch (runtimeexception re) { if (logger.isdebugenabled()) { logger.debug("ignore runtimeexception: cannot update previous revision entity.", re); } } }
Comments
Post a Comment