我对Envers和审核实体有疑问。我有一个现有的应用程序,遗憾的是,它并没有很好地构建,我想在它上面应用envers。 Hibernate已经正常运行了。
在hibernate.cfg.xml中使用这些属性正确配置了Envers(或者至少我相信):
<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" />
创建审核表并使用表的副本和现有修订的外键填充。
没有任何审计工作,这是一个例子: 我想创建一个对象“FAQ”。它有两个String字段,与对象“User”有多对一关系。“User”有12个一对多关系,1个多对一和3个多对多关系。 为了保存“FAQ”对象,我必须设置其“USER”字段,并从数据库中检索: faq.setUser(userDao.getUser(ID)); 我认为以下错误来自于对象之间的关系,但我无法弄清楚原因。
当我尝试保存faq对象时发生错误:
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 ....
等等。我能够提取的唯一有趣信息是这部分:
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)
当我向这个简单对象添加Envers和auditing时,我无法弄清楚为什么会出现stackOverflowError。我尝试保存的每个实体都会发生此错误。 如果您需要更多详细信息,我会尽快回答。