-
Notifications
You must be signed in to change notification settings - Fork 83
-
Hello, I would like to use blaze persistence to query envers revisions of my entities. Thank you ! |
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 2 comments · 8 replies
-
I actually think I misunderstood the example, AuditedView.java is just a way to add the first revision info to the EntityView to get creation information, right ? Thanks |
Beta Was this translation helpful? Give feedback.
All reactions
-
I have seen users use Blaze Persistence with Envers but I am not sure if they queried the Entity_Rev entities directly or created entity mappings to the entity revision table instead. Perhaps someone else rememers (or you can find the issues reported wrt envers back in the issue tracker). Its not possible to use the AuditQuery interface AFAIK. |
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
For entity views to work correctly, there needs to be a Java class representation i.e. a mapping for the data/table. You can either map that explicitly like @jwgmeligmeyling suggested by creating dedicated |
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
Would this be the beginning of a solution to my question ? EnversTest.java |
Beta Was this translation helpful? Give feedback.
All reactions
-
I can't make it work, the auditedEntity is I also tried something taken and updated for hibernate 6 from this repository : public static EntityType<?> getAuditedEntityType(EntityManager em, Class<?> entityType) {
SessionFactoryImplementor session = em.unwrap(SessionImplementor.class).getSessionFactory();
EnversService envers = session.getServiceRegistry().getService(EnversService.class);
String entityName = session.getMappingMetamodel().getEntityDescriptor(entityType).getEntityName();
String auditEntityName = envers.getConfig().getAuditEntityName(entityName);
JpaMetamodel metamodel = session.getJpaMetamodel();
return metamodel.entity(auditEntityName);
} It does return an EntityType corresponding to the audit type but when I use it in a query like so var auditedEntity = getAuditedEntityType(em, entityType);
var cb = cbf.create(em, RevisionCTE.class)
.with(RevisionCTE.class)
.from(auditedEntity, "aud")
.bind("id").select("aud.originalId.rev.id")
.bind("property").select("aud.property")
.end(); I get this error Is there something I need to do for blaze-persistence to know about audit entity types ? |
Beta Was this translation helpful? Give feedback.
All reactions
-
Hibernate by default does not produce a JPA metamodel for Envers entities. You need to set the |
Beta Was this translation helpful? Give feedback.
All reactions
-
Thanks for the quick response, as always 👍🏽 I added the configuration property but it throws an exception, I'll try and make a reproducer over the week-end. The exception : java.lang.RuntimeException: Error injecting com.blazebit.persistence.CriteriaBuilderFactory cloud.ithac.argos.features.protocole.persistence.ProtocoleDAO.cbf
at cloud.ithac.argos.features.protocole.persistence.ProtocoleDAO_Bean.doCreate(Unknown Source)
at cloud.ithac.argos.features.protocole.persistence.ProtocoleDAO_Bean.create(Unknown Source)
at cloud.ithac.argos.features.protocole.persistence.ProtocoleDAO_Bean.create(Unknown Source)
at io.quarkus.arc.impl.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:113)
at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:37)
at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:34)
at io.quarkus.arc.impl.LazyValue.get(LazyValue.java:32)
at io.quarkus.arc.impl.ComputingCache.computeIfAbsent(ComputingCache.java:69)
at io.quarkus.arc.impl.AbstractSharedContext.get(AbstractSharedContext.java:34)
at io.quarkus.arc.impl.ClientProxies.getApplicationScopedDelegate(ClientProxies.java:21)
at cloud.ithac.argos.features.protocole.persistence.ProtocoleDAO_ClientProxy.arc$delegate(Unknown Source)
at cloud.ithac.argos.features.protocole.persistence.ProtocoleDAO_ClientProxy.list(Unknown Source)
at cloud.ithac.argos.features.protocole.persistence.ProtocoleDAOTest.list_should_contain_entity(ProtocoleDAOTest.java:48)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at io.quarkus.test.junit.QuarkusTestExtension.runExtensionMethod(QuarkusTestExtension.java:1015)
at io.quarkus.test.junit.QuarkusTestExtension.interceptTestMethod(QuarkusTestExtension.java:829)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:217)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:213)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:138)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:68)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:147)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:127)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:90)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:55)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:102)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:54)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:118)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:93)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:88)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:62)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
at jdk.proxy1/jdk.proxy1.$Proxy2.stop(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker$3.run(TestWorker.java:193)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:113)
at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:65)
at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
Caused by: jakarta.enterprise.inject.CreationException: Error creating synthetic bean [dd05b93b7e7c10459749f8dfbe4269d396845187]: java.util.ConcurrentModificationException
at com.blazebit.persistence.CriteriaBuilderFactory_dd05b93b7e7c10459749f8dfbe4269d396845187_Synthetic_Bean.doCreate(Unknown Source)
at com.blazebit.persistence.CriteriaBuilderFactory_dd05b93b7e7c10459749f8dfbe4269d396845187_Synthetic_Bean.create(Unknown Source)
at com.blazebit.persistence.CriteriaBuilderFactory_dd05b93b7e7c10459749f8dfbe4269d396845187_Synthetic_Bean.create(Unknown Source)
at io.quarkus.arc.impl.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:113)
at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:37)
at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:34)
at io.quarkus.arc.impl.LazyValue.get(LazyValue.java:32)
at io.quarkus.arc.impl.ComputingCache.computeIfAbsent(ComputingCache.java:69)
at io.quarkus.arc.impl.AbstractSharedContext.get(AbstractSharedContext.java:34)
at com.blazebit.persistence.CriteriaBuilderFactory_dd05b93b7e7c10459749f8dfbe4269d396845187_Synthetic_Bean.get(Unknown Source)
at com.blazebit.persistence.CriteriaBuilderFactory_dd05b93b7e7c10459749f8dfbe4269d396845187_Synthetic_Bean.get(Unknown Source)
... 100 more
Caused by: java.util.ConcurrentModificationException
at java.base/java.util.TreeMap$PrivateEntryIterator.nextEntry(TreeMap.java:1486)
at java.base/java.util.TreeMap$ValueIterator.next(TreeMap.java:1531)
at com.blazebit.persistence.impl.EntityMetamodelImpl.collectColumnNames(EntityMetamodelImpl.java:397)
at com.blazebit.persistence.impl.EntityMetamodelImpl.collectColumnNames(EntityMetamodelImpl.java:357)
at com.blazebit.persistence.impl.EntityMetamodelImpl.<init>(EntityMetamodelImpl.java:127)
at com.blazebit.persistence.impl.CriteriaBuilderFactoryImpl.<init>(CriteriaBuilderFactoryImpl.java:110)
at com.blazebit.persistence.impl.CriteriaBuilderConfigurationImpl.createCriteriaBuilderFactory(CriteriaBuilderConfigurationImpl.java:2078)
at com.blazebit.persistence.integration.quarkus.runtime.EntityViewRecorder.lambda$criteriaBuilderFactorySupplier$0(EntityViewRecorder.java:56)
at io.quarkus.arc.runtime.ArcRecorder$4.apply(ArcRecorder.java:129)
at io.quarkus.arc.runtime.ArcRecorder$4.apply(ArcRecorder.java:126)
at com.blazebit.persistence.CriteriaBuilderFactory_dd05b93b7e7c10459749f8dfbe4269d396845187_Synthetic_Bean.createSynthetic(Unknown Source)
... 111 more And FYI, ProtocoleDAO looks like this : @ApplicationScoped
public class ProtocoleDAO implements [...] {
@Inject
EntityManager em;
@Inject
CriteriaBuilderFactory cbf;
[...]
} |
Beta Was this translation helpful? Give feedback.
All reactions
-
Please create an issue for this problem in the Blaze-Persistence issue tracker and attach a reproducer. |
Beta Was this translation helpful? Give feedback.
All reactions
-
Here it is #1801 |
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
For entity views to work correctly, there needs to be a Java class representation i.e. a mapping for the data/table. You can either map that explicitly like @jwgmeligmeyling suggested by creating dedicated
@Entity
to which you can refer to then, or you can write a@CTE @Entity
and produce these objects through a CTE. You can then model an entity view for that CTE entity. Here is an example on how you can inject the CTE query into the entity view mapping: https://persistence.blazebit.com/documentation/1.6/entity-view/manual/en_US/index.html#using-ctes-in-entity-views