AnsweredAssumed Answered

Programatically modifying rules

Question asked by cmeinck on Mar 21, 2006
I am trying to create a routine that will programatically change the target of a group of move rules I have associated with a space. I am running into a org.springframework.orm.hibernate3.HibernateSystemException:

org.springframework.orm.hibernate3.HibernateSystemException: a different object with the same identifier value was already associated with the session: [org.alfresco.repo.domain.hibernate.NodeImpl#NodeKey[ id=19ec3756-b8ea-11da-bc19-b3df038cb759, protocol=workspace, identifier=SpacesStore]]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [org.alfresco.repo.domain.hibernate.NodeImpl#NodeKey[ id=19ec3756-b8ea-11da-bc19-b3df038cb759, protocol=workspace, identifier=SpacesStore]]::a different object with the same identifier value was already associated with the session: [org.alfresco.repo.domain.hibernate.NodeImpl#NodeKey[ id=19ec3756-b8ea-11da-bc19-b3df038cb759, protocol=workspace, identifier=SpacesStore]]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [org.alfresco.repo.domain.hibernate.NodeImpl#NodeKey[ id=19ec3756-b8ea-11da-bc19-b3df038cb759, protocol=workspace, identifier=SpacesStore]]::a different object with the same identifier value was already associated with the session: [org.alfresco.repo.domain.hibernate.NodeImpl#NodeKey[ id=19ec3756-b8ea-11da-bc19-b3df038cb759, protocol=workspace, identifier=SpacesStore]]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [org.alfresco.repo.domain.hibernate.NodeImpl#NodeKey[ id=19ec3756-b8ea-11da-bc19-b3df038cb759, protocol=workspace, identifier=SpacesStore]]
09:50:56,061 ERROR [ui.common.Utils] Failed to create new space due to error: a different object with the same identifier value was already associated with the session: [org.alfresco.repo.domain.hibernate.NodeImpl#NodeKey[ id=19ec3756-b8ea-11da-bc19-b3df038cb759, protocol=workspace, identifier=SpacesStore]]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [org.alfresco.repo.domain.hibernate.NodeImpl#NodeKey[ id=19ec3756-b8ea-11da-bc19-b3df038cb759, protocol=workspace, identifier=SpacesStore]]
org.springframework.orm.hibernate3.HibernateSystemException: a different object with the same identifier value was already associated with the session: [org.alfresco.repo.domain.hibernate.NodeImpl#NodeKey[ id=19ec3756-b8ea-11da-bc19-b3df038cb759, protocol=workspace, identifier=SpacesStore]]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [org.alfresco.repo.domain.hibernate.NodeImpl#NodeKey[ id=19ec3756-b8ea-11da-bc19-b3df038cb759, protocol=workspace, identifier=SpacesStore]]
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [org.alfresco.repo.domain.hibernate.NodeImpl#NodeKey[ id=19ec3756-b8ea-11da-bc19-b3df038cb759, protocol=workspace, identifier=SpacesStore]]
   at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:154)
   at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:114)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
   at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
   at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
   at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:559)
   at org.hibernate.impl.SessionImpl.save(SessionImpl.java:547)
   at org.hibernate.impl.SessionImpl.save(SessionImpl.java:543)
   at org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:615)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:365)
   at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:612)
   at org.alfresco.repo.node.db.hibernate.HibernateNodeDaoServiceImpl.newNode(HibernateNodeDaoServiceImpl.java:201)
   at sun.reflect.GeneratedMethodAccessor227.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:335)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
   at org.alfresco.repo.transaction.NodeDaoServiceTransactionInterceptor.invoke(NodeDaoServiceTransactionInterceptor.java:61)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
   at $Proxy1.newNode(Unknown Source)
   at org.alfresco.repo.node.db.DbNodeServiceImpl.createNode(DbNodeServiceImpl.java:273)
   at sun.reflect.GeneratedMethodAccessor221.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:335)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:165)
   at $Proxy2.createNode(Unknown Source)
   at sun.reflect.GeneratedMethodAccessor221.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.alfresco.repo.service.StoreRedirectorProxyFactory$RedirectorInvocationHandler.invoke(StoreRedirectorProxyFactory.java:212)
   at $Proxy3.createNode(Unknown Source)
   at sun.reflect.GeneratedMethodAccessor221.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:335)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
   at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:116)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
   at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:80)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:37)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
   at $Proxy15.createNode(Unknown Source)
   at org.alfresco.repo.action.ActionServiceImpl.saveActions(ActionServiceImpl.java:696)
   at org.alfresco.repo.action.ActionServiceImpl.saveActionImpl(ActionServiceImpl.java:592)
   at org.alfresco.repo.rule.RuleServiceImpl.saveRule(RuleServiceImpl.java:606)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:335)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
   at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:116)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
   at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:32)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:37)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
   at $Proxy19.saveRule(Unknown Source)
   at org.alfresco.web.bean.wizard.NewProjectWizard.performCustomProcessing(NewProjectWizard.java:263)
   at org.alfresco.web.bean.wizard.NewSpaceWizard.finish(NewSpaceWizard.java:248)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:129)
   at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)
   at javax.faces.component.UICommand.broadcast(UICommand.java:106)
   at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:90)
   at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:164)
   at org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:316)
   at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)
   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:106)
   at org.alfresco.web.app.servlet.AlfrescoFacesServlet.service(AlfrescoFacesServlet.java:49)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.alfresco.web.app.servlet.AuthenticationFilter.doFilter(AuthenticationFilter.java:73)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)
   at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
   at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
   at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
   at java.lang.Thread.run(Unknown Source)

It always throws the exception at the saveRule call:

//get all old rules on targetNode except inherited rules
List<Rule> ruleList = this.ruleService.getRules(targetNode,false) ;
                  for (Iterator<Rule> rule = ruleList.iterator();rule.hasNext(); )
                  {
                           Rule currentRule = rule.next();
                                                      //remove old move action
                           currentRule.removeAllActions();
                                                      //add new move action                        
   currentRule.addAction(moveAction);
                           this.ruleService.saveRule(targetNode,currentRule);                  
}

From the description of saveRule I thought it would simply overwrite the old rule parameters if the rule you were saving was already associated with it.

Saves the details of the rule to the specified node reference.
If the rule is already associated with the node, the details are updated with those specified.

I think I am misunderstaning how rules are associated with nodes. Any help would be appreciated.

Outcomes