4 Replies Latest reply on Aug 18, 2007 8:48 AM by Christian Bauer

    save the transient instance before flushing

    Olivier Dupont Newbie

      I receive an error when I use this querry in a Statefull Entity (selectApplication):

      return em.createQuery("select a from Application a " +
      "where lower(a.name) like :name " +
      "and lower(a.description) LIKE :description " +
      "and a.category = :category order by a.name")
      .setParameter("name", name)
      .setParameter("description", description)
      .setParameter("category", category);

      I have 2 entities: Application and Category.
      This example comes from DVDStore and the name, description and Category comes from a JSF page:
      <h:selectOneMenu value="#{selectApplication.category}">
      <s:convertEntity />
      <ui:remove> <f:selectItem itemLabel="Any" itemValue="#{anyCategory}" /></ui:remove>
      <s:selectItems value="#{allCategories.resultList}" var="category" label="#{category.name}" noSelectionLabel="ANY" />
      </h:selectOneMenu>

      I receive this error:
      javax.servlet.ServletException: Error calling action method of component with id _id39:_id54
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:152)
      ...
      Caused by: javax.faces.el.EvaluationException: /selectApplication.xhtml @48,51 action="#{selectApplication.doSearch}": javax.ejb.EJBTransactionRolledbackException: java.lang.IllegalStateException: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.mycompany.seam.refdata.model.Category
      at com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.java:73)

        • 1. Re: save the transient instance before flushing
          Christian Bauer Master

          Well, looks like the persistence context is flushed before you execute that query, because the query touches entities that have been modified. Either enable cascading persist on the association from Category to Application (I'm guessing here that this is the association in question), or call persist() on the Category instance before flushing/querying, or disable automatic flushing with FlushModeType.MANUAL by using a Seam-managed persistence context.

          • 2. Re: save the transient instance before flushing
            Harry Holt Newbie

            I'm getting a similar error, and as a SEAM newbie, I can't figure out how to fix it.

            I used seam-gen to create a new project, then used new-entity. The resulting components allow me to create and edit, but the "delete" button produces the TransientObjectException:

            16:08:25,384 ERROR [ExceptionFilter] exception root cause
            javax.faces.FacesException: #{commentHome.remove}: org.hibernate.TransientObjectException:
             object references an unsaved transient instance - save the transient instance before flus
            hing: gov.virginia.vec.IT.prov.Comment
             at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.j
            ava:107)
             at javax.faces.component.UICommand.broadcast(UICommand.java:383)
             at org.ajax4jsf.framework.ajax.AjaxViewRoot.processEvents(AjaxViewRoot.java:180)
             at org.ajax4jsf.framework.ajax.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:158)
            
             at org.ajax4jsf.framework.ajax.AjaxViewRoot.processApplication(AjaxViewRoot.java:3
            46)
             at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.j
            ava:97)
             at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
             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(ApplicationFil
            terChain.java:290)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain
            .java:206)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:82)
             at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:68)
             at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:68)
             at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:68)
             at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:44)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:68)
             at org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.j
            ava:127)
             at org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:277)
             at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:68)
             at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:68)
             at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:149)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFil
            terChain.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(ApplicationFil
            terChain.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(SecurityAssociati
            onValve.java:179)
             at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.ja
            va: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(CachedConnectionV
            alve.java:157)
             at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:10
            9)
             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(Http11P
            rotocol.java:580)
             at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
             at java.lang.Thread.run(Thread.java:595)
            Caused by: javax.faces.el.EvaluationException: org.hibernate.TransientObjectException: obj
            ect references an unsaved transient instance - save the transient instance before flushing
            : gov.virginia.vec.IT.prov.Comment
             at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBinding
            MethodExpressionAdapter.java:91)
             at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.j
            ava:91)
             ... 45 more
            


            • 3. Re: save the transient instance before flushing
              Harry Holt Newbie

              Ok, is this a problem in the CVS version of org.jboss.seam.framework.EntityHome, or is it just me?

              In the seam-gen created [entity]Home.java class, if I do this:

               log.info("Entity name: " + super.getEntityName());
               log.info("persist result: " + super.persist());
               log.info("remove result: " + super.remove());
              


              I get the correct entity name, "persisted" is returned from the persist method, but then the above-reference exception when it gets to the remove().

              I don't see any Hibernate commands on the log when calling persist, so maybe that is not working? The "Hibernate: delete ... " is written right before the exception.



              • 4. Re: save the transient instance before flushing
                Christian Bauer Master

                This was caused by getEntityName() in EntityHome and has been fixed in CVS.