1 Reply Latest reply on Dec 2, 2013 5:44 AM by sylflip

    StackOverflowError : Can't save object with Envers

    sylflip

      Hi,

      I have a problem with Envers and auditing entities. I have an existing application which, unfortunately, isn't really well built, and I'd like to apply envers on it.
      Hibernate was already working properly.

       

      Envers is configured correctly (or at least I believe so) with these properties in the hibernate.cfg.xml :

       

      <property name="org.hibernate.envers.audit_strategy">org.hibernate.envers.strategy.ValidityAuditStrategy</property>

       

      <listener class="org.hibernate.envers.event.AuditEventListener"type="post-insert" />
      <listener class="org.hibernate.envers.event.AuditEventListener"type="post-update" />
      <listener class="org.hibernate.envers.event.AuditEventListener"type="post-delete" />
      <listener class="org.hibernate.envers.event.AuditEventListener"type="pre-collection-update" />
      <listener class="org.hibernate.envers.event.AuditEventListener"type="pre-collection-remove" />
      <listener class="org.hibernate.envers.event.AuditEventListener"type="post-collection-recreate" />

       

      The auditing tables are created and populated with a copy of the tables, and a foreign key to an existing revision.

       

      None of the audit works, and here is an example :

      I want to create an object "FAQ". It has two String field, and a many-to-one relation with the object "User"."User" has 12 one-to-many relationships, 1 many-to-one and 3 many-to-many.

      In order to save the "FAQ" object, I have to set its "USER" field, with the one retrieve from the database :
      faq.setUser(userDao.getUser(id));

      I think the following error comes from the relation between the object, but I can't really figure out why.

       

       

      The error occur when I try to save the faq object :

       

      Caused by: java.lang.StackOverflowError

           at java.util.HashMap.entrySet(HashMap.java:480)

           at java.util.AbstractMap.hashCode(AbstractMap.java:434)

           at java.util.MapEntry.hashCode(MapEntry.java:75)

           at ....

       

      And so on. The only interesting information I've been able to extract is this part :

       

      at java.util.HashMap.get(HashMap.java:498)
      at org.apache.bval.jsr303.GroupValidationContextImpl.collectValidated(GroupValidationContextImpl.java:133)
      at org.apache.bval.jsr303.ClassValidator.validateBeanNet(ClassValidator.java:421)
      at org.apache.bval.jsr303.ClassValidator.validate(ClassValidator.java:141)
      at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:136)
      at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreUpdate(BeanValidationEventListener.java:102)
      at org.hibernate.action.EntityUpdateAction.preUpdate(EntityUpdateAction.java:237)
      at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:86)
      at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:185)
      at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
      at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
      at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
      at org.hibernate.envers.synchronization.AuditProcess.doBeforeTransactionCompletion(AuditProcess.java:155)
      at org.hibernate.engine.ActionQueue$BeforeTransactionCompletionProcessQueue.beforeTransactionCompletion(ActionQueue.java:543)
      at org.hibernate.engine.ActionQueue.beforeTransactionCompletion(ActionQueue.java:216)
      at org.hibernate.impl.SessionImpl.beforeTransactionCompletion(SessionImpl.java:571)
      at org.hibernate.jdbc.JDBCContext.beforeTransactionCompletion(JDBCContext.java:250)
      at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:138)
      at com.my_company.business.controller.GenericBusinessController.endOperation(GenericBusinessController.java:86)
      at com.my_company.business.controller.referentiel.FaqBusinessController.enregistrer(FaqBusinessController.java:104)
      at com.my_company.business.controller.referentiel.FaqBusinessController.enregistrer(FaqBusinessController.java:24)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
      at java.lang.reflect.Method.invoke(Method.java:611)
      at com.ideo.sweetdev.core.service.remoting.ServerRemotingService.invokeMethod(ServerRemotingService.java:402)
      at com.ideo.sweetdev.core.service.remoting.ServerRemotingService.executeEvent(ServerRemotingService.java:255)
      at com.my_company.ejb.EjbFacade.execute(EjbFacade.java:41)
      at com.my_company.ejb.EJSRemote0SLEjbFacade_9c04bdc1.execute(EJSRemote0SLEjbFacade_9c04bdc1.java)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
      at java.lang.reflect.Method.invoke(Method.java:611)
      at com.ibm.rmi.util.ProxyUtil$4.run(ProxyUtil.java:609)
      at java.security.AccessController.doPrivileged(AccessController.java:254)
      at com.ibm.rmi.util.ProxyUtil.invokeWithClassLoaders(ProxyUtil.java:606)
      at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDelegate.java:1177)
      at $Proxy44.execute(Unknown Source)
      at com.my_company.ejb._EjbFacadeRemote_Stub.execute(_EjbFacadeRemote_Stub.java)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
      at java.lang.reflect.Method.invoke(Method.java:611)
      at com.ideo.sweetdev.core.util.ReflectHelper.invokeMethod(ReflectHelper.java:485)
      at com.ideo.sweetdev.core.service.broker.ejbconnector.EJBConnector.invokeMethod(EJBConnector.java:206)
      at com.ideo.sweetdev.core.service.broker.ejbconnector.EJBConnector.execute(EJBConnector.java:110)
      at com.ideo.sweetdev.core.service.broker.Broker.executeService(Broker.java:369)
      at com.ideo.sweetdev.core.service.broker.Broker.execute(Broker.java:252)
      at com.ideo.sweetdev.core.service.remoting.RemotingService.invokeBusinessMethod(RemotingService.java:156)
      at com.ideo.sweetdev.core.service.remoting.RemotingInvocationHandler.invoke(RemotingInvocationHandler.java:67)

       

       

      I can't figure out why there's a stackOverflowError when I add Envers and auditing to this simple object. This error occurs for every entity I try to save.

      Thank's in advance, if you need more details, I'll answer as quick as I can.

       

      Sylvain