1 Reply Latest reply on Jun 27, 2011 8:30 AM by Leo van den berg

    Problem deleting a record that's being referenced

    Sam H Newbie


      Hi guys,


      I am using Weblogic 10.3 with Seam 2.2.1 Final, MSSQL 2005, richfaces


      Using the seam-gen generated code, when I try to delete a table record that has children (i.e. referenced by
      another table), the browser will time out with the error messages


           The page isn't redirecting properly
             
                Firefox has detected that the server is redirecting the request for this address in a way that will never complete.


      -- Error messages in log file




      java.lang.IllegalStateException: Transaction already active
           at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:35)
           at org.jboss.seam.transaction.EntityTransaction.begin(EntityTransaction.java:82)
           at org.jboss.seam.jsf.SeamPhaseListener.begin(SeamPhaseListener.java:592)
           at org.jboss.seam.jsf.SeamPhaseListener.begin(SeamPhaseListener.java:582)
           at org.jboss.seam.jsf.SeamPhaseListener.handleTransactionsBeforePhase(SeamPhaseListener.java:326)
           at org.jboss.seam.jsf.SeamPhaseListener.beforeServletPhase(SeamPhaseListener.java:143)
           at org.jboss.seam.jsf.SeamPhaseListener.beforePhase(SeamPhaseListener.java:117)
           at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:218)
           at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
           at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
           at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
           at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
           at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
           at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
           at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
           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:45)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
           at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
           at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
           at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
           at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
           at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
           at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
           at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
           at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3502)
           at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
           at weblogic.security.service.SecurityManager.runAs(Unknown Source)
           at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2186)
           at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2092)
           at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)
           at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
           at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)





      I believe the root cause is SQL constraint but log suggests otherwise. Deleting a record without
      children record is fine.


      Ideally, it should be a SQL/hibernate exception so I can catch it and redirect to error page.
      Workaround I think of is to check if record has any children before delete, if yes, then no delete
      but redirect back to same page with message explaining why it can't be deleted.


      I was wandering if anyone has seen this before and know of a better solution?


      Thanks


      Sam





            

        • 1. Re: Problem deleting a record that's being referenced
          Leo van den berg Master

          Hi,


          I've seen this messages a lot prior to understanding how persistency really works. It's all about mapping you entities correctly (this is basic JPA and has not much to do with Seam).


          You must annotate your class relation in such a way that your persistency provider knows what to do. If the children must be deleted when the parent is deleted, you must add the apprpiate CascadeType (cascade-field) or use a CollectionOfElements in combination with the delete children cacade.


          Leo