[jboss-user] [JBoss Seam] - hibernate tries to persist a second time

bobbele do-not-reply at jboss.com
Wed Nov 14 10:26:44 EST 2007


hi,
i am not sure if this is a seam or/and hibernate problem, so i try to ask here =)
following scenario: 
i have a message that consists of child nodes, files in this case. the user opens a site where he can change the properties of an existing message and add/delete filenodes (using seam fileuploader), this site is backed by a SFSB.
so the user adds two new files to the message, nothing is saved until he presses the submit button. then a method checks for the changes made and syncs them with the db, the code for the filenodes is:
		
  | for (FileNode file : fileListadded) {
  |    if (!message.getChildren().contains(file)) {
  |       file.setParentNode(message);
  |       message.getChildren().add(file);
  |       file.setContentOwner(message.getContentOwner()); // messagebox
  |       entitymanager.persist(file);
  |       entitymanager.flush();
  |    }
  | }
  | [...]
  | // update the message via merge
  | 
everything works fine, the changes are synced, the new filenodes are persisted to the db. after that i raise an event so that another controller, which manages different messageboxes, knows that a message has changed.

  | saveChangesOnExistingItem(message);
  | // SeamEvent is my private container for custom events
  | Events.instance().raiseEvent(SeamEvents.EVENT_VIEWMODEL_MESSAGE_CHANGED);
  | return JSFOutcomes.OUTCOME_EDIT_COMPLETED;
  | 
so the changes are saved, the event raised (the messageboxcontroller updates which messagebox to display) and the outcome redirects to the messagebox display, it shows the box which is the parent of the edited message.
the problem is that hibernate tries to persist the new filenodes again after the outcome is returned. so the exceptions is thrown before the page is displayed.
stack trace:
javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: com.sielog.wpz.model.contentrepo.ContentNode
  | 	at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:629)
  | 	at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:524)
  | 	at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:114)
  | 	at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:249)
  | 	at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:88)
  | 	at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
  | 	at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1256)
  | 	at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135)
  | 	at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:87)
  | 	at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:140)
  | 	at org.jboss.seam.transaction.UTTransaction.commit(UTTransaction.java:52)
  | 	at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:581)
  | 	at org.jboss.seam.jsf.SeamPhaseListener.handleTransactionsAfterPhase(SeamPhaseListener.java:325)
  | 	at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:226)
  | 	at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:184)
  | 	at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:280)
  | 	at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
  | 	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
  | 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
  | 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  | 	at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:80)
  | 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
  | 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  | 	at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
  | 	at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
  | 	at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
  | 	at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:80)
  | 	at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
  | 	at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
  | 	at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
  | 	at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:44)
  | 	at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
  | 	at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
  | 	at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
  | 	at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
  | 	at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
  | 	at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
  | 	at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
  | 	at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:150)
  | 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
  | 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  | 	at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
  | 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
  | 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  | 	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
  | 	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
  | 	at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
  | 	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
  | 	at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
  | 	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
  | 	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
  | 	at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
  | 	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
  | 	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
  | 	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
  | 	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
  | 	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
  | 	at java.lang.Thread.run(Unknown Source)
  | Caused by: org.hibernate.PersistentObjectException: detached entity passed to persist: com.sielog.wpz.model.contentrepo.ContentNode
  | 	at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:79)
  | 	at org.hibernate.impl.SessionImpl.firePersistOnFlush(SessionImpl.java:644)
  | 	at org.hibernate.impl.SessionImpl.persistOnFlush(SessionImpl.java:636)
  | 	at org.hibernate.engine.CascadingAction$9.cascade(CascadingAction.java:323)
  | 	at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
  | 	at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
  | 	at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
  | 	at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:296)
  | 	at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:242)
  | 	at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:219)
  | 	at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
  | 	at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
  | 	at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:131)
  | 	at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:122)
  | 	at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65)
  | 	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
  | 	at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
  | 	at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
  | 	at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:515)
  | 	... 56 more
  | 16:08:12,265 ERROR [SeamPhaseListener] uncaught exception
  | java.lang.IllegalStateException: Could not commit transaction
  | 	at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:591)
  | 	at org.jboss.seam.jsf.SeamPhaseListener.handleTransactionsAfterPhase(SeamPhaseListener.java:325)
  | 	at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:226)
  | 	at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:184)
  | 	at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:280)
  | 	at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
  | 	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
  | 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
  | 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  | 	at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:80)
  | 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
  | 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  | 	at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
  | 	at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
  | 	at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
  | 	at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:80)
  | 	at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
  | 	at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
  | 	at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
  | 	at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:44)
  | 	at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
  | 	at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
  | 	at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
  | 	at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
  | 	at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
  | 	at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
  | 	at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
  | 	at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:150)
  | 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
  | 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  | 	at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
  | 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
  | 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  | 	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
  | 	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
  | 	at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
  | 	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
  | 	at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
  | 	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
  | 	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
  | 	at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
  | 	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
  | 	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
  | 	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
  | 	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
  | 	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
  | 	at java.lang.Thread.run(Unknown Source)
  | Caused by: javax.transaction.RollbackException: [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] Can't commit because the transaction is in aborted state
  | 	at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1267)
  | 	at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135)
  | 	at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:87)
  | 	at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:140)
  | 	at org.jboss.seam.transaction.UTTransaction.commit(UTTransaction.java:52)
  | 	at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:581)
  | 	... 46 more
  | Caused by: javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: com.sielog.wpz.model.contentrepo.ContentNode
  | 	at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:629)
  | 	at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:524)
  | 	at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:114)
  | 	at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:249)
  | 	at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:88)
  | 	at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
  | 	at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1256)
  | 	... 51 more
  | Caused by: org.hibernate.PersistentObjectException: detached entity passed to persist: com.sielog.wpz.model.contentrepo.ContentNode
  | 	at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:79)
  | 	at org.hibernate.impl.SessionImpl.firePersistOnFlush(SessionImpl.java:644)
  | 	at org.hibernate.impl.SessionImpl.persistOnFlush(SessionImpl.java:636)
  | 	at org.hibernate.engine.CascadingAction$9.cascade(CascadingAction.java:323)
  | 	at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
  | 	at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
  | 	at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
  | 	at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:296)
  | 	at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:242)
  | 	at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:219)
  | 	at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
  | 	at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
  | 	at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:131)
  | 	at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:122)
  | 	at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65)
  | 	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
  | 	at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
  | 	at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
  | 	at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:515)
  | 	... 56 more
  | 
any suggestions appreciated, thanks!

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4104643#4104643

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4104643



More information about the jboss-user mailing list