2 Replies Latest reply on Oct 14, 2015 10:58 AM by jimmonen

    Hibernate Envers: AuditQuery throws ClasscastException

    Petteri Pertola Newbie

      Hello,

       

      I have a basic entity called Report, which is annotated with @Audited annotation. Changes to the entity are being stored in the database correctly by envers, where I have a number of revisions for the Report entity ID 1.

      The following code is being used by my DAO class to retrieve a a list of all revisions from the audit table:

      AuditReader auditReader = AuditReaderFactory.get(sessionFactory.getCurrentSession());
      AuditQuery query = auditReader.createQuery().forRevisionsOfEntity(Report.class, true, true);
      query.add(AuditEntity.id().eq(1)
      List<Object[]> auditList = query.getResultList();
      

       

      The last line in this code snippet throws the following exception, and I can't seem to figure out why. Could anyone help with this one? I am trying to retrieve a list of all revisions to the Report entity.

       

      Java.lang.ClassCastException: org.hibernate.envers.DefaultRevisionEntity_$$_javassist_2 cannot be cast to javassist.util.proxy.Proxy
      at org
      .hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxy(JavassistLazyInitializer.java:148)
      at org
      .hibernate.proxy.pojo.javassist.JavassistProxyFactory.getProxy(JavassistProxyFactory.java:73)
      at org
      .hibernate.tuple.entity.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:758)
      at org
      .hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:4419)
      at org
      .hibernate.event.internal.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:333)
      at org
      .hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:259)
      at org
      .hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:151)
      at org
      .hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1017)
      at org
      .hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:944)
      at org
      .hibernate.type.EntityType.resolveIdentifier(EntityType.java:671)
      at org
      .hibernate.type.EntityType.resolve(EntityType.java:489)
      at org
      .hibernate.type.ComponentType.resolve(ComponentType.java:667)
      at org
      .hibernate.loader.Loader.extractKeysFromResultSet(Loader.java:835)
      at org
      .hibernate.loader.Loader.getRowFromResultSet(Loader.java:714)
      at org
      .hibernate.loader.Loader.processResultSet(Loader.java:949)
      at org
      .hibernate.loader.Loader.doQuery(Loader.java:917)
      at org
      .hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:348)
      at org
      .hibernate.loader.Loader.doList(Loader.java:2548)
      at org
      .hibernate.loader.Loader.doList(Loader.java:2534)
      at org
      .hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2364)
      at org
      .hibernate.loader.Loader.list(Loader.java:2359)
      at org
      .hibernate.loader.hql.QueryLoader.list(QueryLoader.java:495)
      at org
      .hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:357)
      at org
      .hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)
      at org
      .hibernate.internal.SessionImpl.list(SessionImpl.java:1194)
      at org
      .hibernate.internal.QueryImpl.list(QueryImpl.java:101)
      at org
      .hibernate.envers.query.impl.AbstractAuditQuery.buildAndExecuteQuery(AbstractAuditQuery.java:100)
      at org
      .hibernate.envers.query.impl.RevisionsOfEntityQuery.list(RevisionsOfEntityQuery.java:112)
      at org
      .hibernate.envers.query.impl.AbstractAuditQuery.getSingleResult(AbstractAuditQuery.java:110)
      at com
      .nordea.cms.art.cto.reporting.spring.dao.ReportsDao.getReportVersions(ReportsDao.java:137)
      at com
      .nordea.cms.art.cto.reporting.spring.dao.ReportsDao$$FastClassByCGLIB$$ce386fbe.invoke(<generated>)
      at org
      .springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
      at org
      .springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698)
      at org
      .springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
      at org
      .springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
      at org
      .springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
      at org
      .springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
      at org
      .springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      at org
      .springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631)
      at com
      .nordea.cms.art.cto.reporting.spring.dao.ReportsDao$$EnhancerByCGLIB$$7b386dc3.getReportVersions(<generated>)
      at com
      .nordea.cms.art.cto.reporting.spring.service.ReportsService.getReportVersions(ReportsService.java:80)
      at com
      .nordea.cms.art.cto.reporting.spring.controllers.ReportsController.showReports(ReportsController.java:84)
      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
      .springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
      at org
      .springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
      at org
      .springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
      at org
      .springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
      at org
      .springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
      at org
      .springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
      at org
      .springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
      at org
      .springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
      at org
      .springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
      at org
      .springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
      at javax
      .servlet.http.HttpServlet.service(HttpServlet.java:731)
      at org
      .springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
      at javax
      .servlet.http.HttpServlet.service(HttpServlet.java:844)
      at weblogic
      .servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280)
      at weblogic
      .servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254)
      at weblogic
      .servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136)
      at weblogic
      .servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:341)
      at weblogic
      .servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:238)
      at weblogic
      .servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3363)
      at weblogic
      .servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3333)
      at weblogic
      .security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
      at weblogic
      .security.service.SecurityManager.runAs(SecurityManager.java:120)
      at weblogic
      .servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
      at weblogic
      .servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2220)
      at weblogic
      .servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2146)
      at weblogic
      .servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2124)
      at weblogic
      .servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1564)
      at weblogic
      .servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:254)
      at weblogic
      .work.ExecuteThread.execute(ExecuteThread.java:295)
      at weblogic
      .work.ExecuteThread.run(ExecuteThread.java:254)