Note that there are some explanatory texts on larger screens.

plurals
  1. POenvers: get audited entities referencing to entities that are not audited
    primarykey
    data
    text
    <p>I'm having issues when trying to get audited entities referencing to entities that are not audited. In our application, certain entities are bootstrapped without the use of hibernate, those entities are our meta-model and do not need to be audited.</p> <h3>Working example:</h3> <pre><code>public class A { private String id; private List&lt;B&gt; attributeReferences; } public class B { private String id; private A attributeReference; } </code></pre> <p>If I execute the code: </p> <pre><code>A rev1 = getAuditReader().find(A.class, "foo", 1); A rev2 = getAuditReader().find(A.class, "foo", 2); A rev3 = getAuditReader().find(A.class, "foo", 3); </code></pre> <p>Everything goes well, however if I try to get a version of B the error occurs: </p> <pre><code>B rev2 = getAuditReader().find(B.class, "bar", 2); </code></pre> <p>org.hibernate.ObjectNotFoundException: No row with the given identifier exists [metafoo]</p> <p>Envers successfully does the lookup of the B entity with a lazy reference to my metafoo entity. However when trying to store that in its cache the hashcode method of my B entity gets called, which in turn does a lookup for metafoo which does not exist in the audit tables, raising the exception.</p> <p>Is there a way I could ignore those inexistent references instead of throwing this error? (maybe by excluding such references in the query)</p> <p>How to deal with inexistent data altogether (suppose we deleted all entries older than 1 month from the audit table) how could we still query entities referencing to inexistent ones?</p> <h3>PS:</h3> <p>I'd like not to modify the hashcode function if possible<br> I'd like not to audit my meta model </p> <h3>Table structure:</h3> <p>table A: </p> <pre><code>ID ---------------------------------------- metaFooAttribute fooAttribute foo </code></pre> <p>table A_AUD: </p> <pre><code>REV REVTYPE ID ---------------------------------------- 1 0 fooAttribute 1 0 foo 2 1 foo 3 1 foo </code></pre> <p>table B: </p> <pre><code>ID ---------------------------------------- bar </code></pre> <p>table B_AUD: </p> <pre><code>REV REVTYPE ID ATTRIBUTE_ID ---------------------------------------- 1 0 bar metaFooAttribute 1 0 bar fooAttribute 2 1 bar fooAttribute </code></pre> <h3>Stacktrace:</h3> <pre><code>org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [playground.test.A#metafoo] at org.hibernate.impl.SessionFactoryImpl$2.handleEntityNotFound(SessionFactoryImpl.java:435) at org.hibernate.proxy.AbstractLazyInitializer.checkTargetState(AbstractLazyInitializer.java:189) at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:178) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:215) at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:189) at playground.test.A$$EnhancerByCGLIB$$3cdb0441.hashCode(&lt;generated&gt;) at playground.test.B.hashCode(B.java:120) at org.hibernate.envers.tools.Triple.hashCode(Triple.java:73) at java.util.HashMap.put(HashMap.java:372) at org.hibernate.envers.reader.FirstLevelCache.putOnEntityNameCache(FirstLevelCache.java:94) at org.hibernate.envers.entities.EntityInstantiator.createInstanceFromVersionsEntity(EntityInstantiator.java:105) at org.hibernate.envers.entities.EntityInstantiator.addInstancesFromVersionsEntities(EntityInstantiator.java:113) at org.hibernate.envers.query.impl.EntitiesAtRevisionQuery.list(EntitiesAtRevisionQuery.java:110) at org.hibernate.envers.query.impl.AbstractAuditQuery.getSingleResult(AbstractAuditQuery.java:108) at org.hibernate.envers.reader.AuditReaderImpl.find(AuditReaderImpl.java:119) at org.hibernate.envers.reader.AuditReaderImpl.find(AuditReaderImpl.java:94) at playground.test.TestEnvers.testGetAttribute(TestActivityStream.java:60) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner.run(ParentRunner.java:300) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) </code></pre> <h3>Edit:</h3> <p>I found this <a href="https://stackoverflow.com/questions/11449611/how-not-to-audit-a-join-table-and-related-entities-using-hibernate-envers">post</a> interesting but it does not solve the problem as my reference is of type A so the annotation @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED) does not work.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload