7 Replies Latest reply on Jan 4, 2008 7:32 AM by Techie Exchange

    Database flush problem

    Mirko Adari Novice

      We have non-seam component entity - Client.class
      We outject it to session context while logging in:

       @In(required = false, value="client")
       @Out(value = "client", required = false, scope = ScopeType.SESSION)
       private Client user;
       @In
       private EntityManager em;
       public boolean authenticate() {
       try {
       user = (Client) em.createQuery(
       "from Client where email = :username and password = :password").setParameter("username", Identity.instance().getUsername()).setParameter("password", sha1(Identity.instance().getPassword())).getSingleResult();
       }
      


      The client is outjected to session scope ( seen from debug.seam)
      So then we have a page with a form to change client`s data.
      <ice:form>
       <h:inputText id="firmName" styleClass="w120" value="#{client.name}"/>
       <ice:commandButton action="update" />
      </ice:form>
      

      When I press the button, the data is changed inside client in session scope (debug.seam).
      But this data is not flushed to database. I am using SMPC and it is extended persistence context right? Therefore all the entities retrieved from entitymanager (client is retrieved from smpc as seen in code example) should get automatically flushed. When I log out the modified data is lost and new login has old values.
      Am I missing a point here?

        • 1. Re: Database flush problem
          Shane Bryzak Master

          Seam-managed persistence contexts are conversation-scoped, so you'll need to use em.merge() to merge the changes in your session-scoped (i.e. unmanaged) entity.

          • 2. Re: Database flush problem
            Mirko Adari Novice

            Merging gave me following stacktrack:

            uncaught exception
            java.lang.IllegalStateException: Could not commit transaction
             at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:592)
             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 com.icesoft.faces.webapp.http.core.JsfLifecycleExecutor.apply(JsfLifecycleExecutor.java:17)
             at com.icesoft.faces.webapp.http.core.ReceiveSendUpdates.renderCyclePartial(ReceiveSendUpdates.java:67)
             at com.icesoft.faces.webapp.http.core.ReceiveSendUpdates.service(ReceiveSendUpdates.java:43)
             at com.icesoft.faces.webapp.http.core.IDVerifier.service(IDVerifier.java:25)
             at com.icesoft.faces.webapp.http.core.ViewBoundServer.service(ViewBoundServer.java:52)
             at com.icesoft.faces.webapp.http.common.standard.PathDispatcherServer$Matcher.serviceOnMatch(PathDispatcherServer.java:50)
             at com.icesoft.faces.webapp.http.common.standard.PathDispatcherServer.service(PathDispatcherServer.java:19)
             at com.icesoft.faces.webapp.http.servlet.ThreadBlockingAdaptingServlet.service(ThreadBlockingAdaptingServlet.java:19)
             at com.icesoft.faces.webapp.http.servlet.EnvironmentAdaptingServlet.service(EnvironmentAdaptingServlet.java:29)
             at com.icesoft.faces.webapp.http.servlet.MainSessionBoundServlet.service(MainSessionBoundServlet.java:117)
             at com.icesoft.faces.webapp.http.servlet.SessionDispatcher.service(SessionDispatcher.java:37)
             at com.icesoft.faces.webapp.http.servlet.PathDispatcher$Matcher.serviceOnMatch(PathDispatcher.java:52)
             at com.icesoft.faces.webapp.http.servlet.PathDispatcher.service(PathDispatcher.java:29)
             at com.icesoft.faces.webapp.http.servlet.MainServlet.service(MainServlet.java:76)
             at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
             at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
             at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:855)
             at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:703)
             at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:542)
             at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:440)
             at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:366)
             at com.icesoft.faces.webapp.xmlhttp.BlockingServlet.service(BlockingServlet.java:54)
             at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:317)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
             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:85)
             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.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
             at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
             at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
             at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:288)
             at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
             at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
             at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
             at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
             at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
             at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
             at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
             at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
             at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
             at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
             at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
             at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
             at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
             at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
             at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
             at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:272)
             at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
             at com.sun.enterprise.web.connector.grizzly.comet.CometEngine.executeServlet(CometEngine.java:547)
             at com.sun.enterprise.web.connector.grizzly.comet.CometEngine.handle(CometEngine.java:299)
             at com.sun.enterprise.web.connector.grizzly.comet.CometAsyncFilter.doFilter(CometAsyncFilter.java:87)
             at com.sun.enterprise.web.connector.grizzly.async.DefaultAsyncExecutor.invokeFilters(DefaultAsyncExecutor.java:175)
             at com.sun.enterprise.web.connector.grizzly.async.DefaultAsyncExecutor.interrupt(DefaultAsyncExecutor.java:153)
             at com.sun.enterprise.web.connector.grizzly.async.AsyncProcessorTask.doTask(AsyncProcessorTask.java:92)
             at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
             at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
            Caused by: javax.transaction.RollbackException: Transaction marked for rollback.
             at com.sun.enterprise.distributedtx.J2EETransaction.commit(J2EETransaction.java:440)
             at com.sun.enterprise.distributedtx.J2EETransactionManagerOpt.commit(J2EETransactionManagerOpt.java:371)
             at com.sun.enterprise.distributedtx.UserTransactionImpl.commit(UserTransactionImpl.java:197)
             at org.jboss.seam.transaction.UTTransaction.commit(UTTransaction.java:52)
             at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:582)
             ... 74 more
            
            
            

            Code:
            @In
             EntityManager em;
             @In
             @Out(scope=ScopeType.SESSION)
             Client client;
             public void update() {
             client = em.merge(client);
             }
            


            • 4. Re: Database flush problem
              Mirko Adari Novice

              It seems like a something basic. Doesn`t anyone have an idea?

              • 5. Re: Database flush problem
                Techie Exchange Newbie

                Hi,
                SMPC - SeamManagedPersistenceContext is default to conversation-scoped. You can change that in components.xml

                <persistence:managed-persistence-context
                 scope="session"
                 name="em"
                 auto-create="true"
                 entity-manager-factory="#{yourDatabase}"/>
                


                Now try again.

                • 6. Re: Database flush problem
                  Christian Bauer Master

                  This is most definitely a very very bad idea. Persistence contexts should (almost) never be scoped to the users session.

                  • 7. Re: Database flush problem
                    Techie Exchange Newbie

                     

                    "christian.bauer@jboss.com" wrote:
                    This is most definitely a very very bad idea. Persistence contexts should (almost) never be scoped to the users session.


                    You're absolutely right. I want to give a warning about it but i forgot.

                    As PC is conversation-scoped (always recommended), original post request for auto-flush without any explicit (persist or merge) is not possible i think and moreover this situation is normal.

                    What's your opinion?