8 Replies Latest reply on Oct 2, 2008 11:30 AM by Adam Warski

    JBoss Seam and flushModel=manual

    Andrew Wheeler Newbie

      An exception is thrown if I update a versioned entity when flushMode=manual for the page e.g:

       <begin-conversation join="true" flush-mode="manual"/>
      


      Exception:
      2008-08-27 12:09:05,996 INFO [org.jboss.resource.connectionmanager.CachedConnectionManager] Closing a connection for you. Please close them yourself: org.jboss.resource.adapter.jdbc.WrappedConnection@1714ea1
      java.lang.Throwable: STACKTRACE
       at org.jboss.resource.connectionmanager.CachedConnectionManager.registerConnection(CachedConnectionManager.java:290)
       at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:417)
       at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:842)
       at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:88)
       at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:47)
       at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:423)
       at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
       at org.hibernate.jdbc.BorrowedConnectionProxy.invoke(BorrowedConnectionProxy.java:50)
       at $Proxy259.prepareStatement(Unknown Source)
       at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:505)
       at org.hibernate.jdbc.AbstractBatcher.prepareSelectStatement(AbstractBatcher.java:123)
       at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:73)
       at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:99)
       at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
       at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
       at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
       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:535)
       at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
       at org.jboss.envers.synchronization.VersionsSync.generateRevision(VersionsSync.java:56)
       at org.jboss.envers.synchronization.VersionsSync.executeInSession(VersionsSync.java:101)
       at org.jboss.envers.synchronization.VersionsSync.beforeCompletion(VersionsSync.java:126)
       at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:114)
       at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:247)
       at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:86)
       at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
       at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1389)
       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:603)
       at org.jboss.seam.jsf.SeamPhaseListener.handleTransactionsAfterPhase(SeamPhaseListener.java:341)
       at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:241)
       at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:192)
       .
       .
       .
      




        • 1. Re: JBoss Seam and flushModel=manual
          Adam Warski Master

          Hello,

          that's strange - I've been testing manual flush modes, but somehow Seam must be doing it differently :).

          What version of Seam and AS are you using? Maybe you have a sample Seam application demonstrating this?

          If possible, please create a jira issue (http://jira.jboss.org/jira/browse/ENVERS).

          Thanks,
          Adam

          • 2. Re: JBoss Seam and flushModel=manual
            Adam Warski Master

            Hello,

            I've created a small test application and I'm getting the same exception. It doesn't really prevent any writes, nor does it rollback the transaction - it's more of a warning.

            Anyway, I've fixed this (ENVERS-46) and commited the changes to trunk.

            --
            Adam

            • 3. Re: JBoss Seam and flushModel=manual
              Vladimir Kovalyuk Apprentice

              Can Enver cope with Seam-managed-persistence-context in manual flush mode?
              I remember investigating on this. When flush() occurs entity listeners are called. If listener persist something to DB it will remain in the context but still unflushed. Seam team doesn't care of it 'cause it is inconsistent with JPA spec.

              • 4. Re: JBoss Seam and flushModel=manual
                Adam Warski Master

                Hello,

                yes, that's how I tested it, and it worked fine. If the flush mode is manual, I open a temporary session (there's a special method for that in Hibernate) and use that session to persist the versioning data. I can flush this temporary session at will.

                --
                Adam

                • 5. Re: JBoss Seam and flushModel=manual
                  Erik Bakstad Newbie

                  Hi,

                  I'm having a similar problem, only I'm using envers-1.1.0.beta2 and hiberante 3.3.x.

                  Same problem as fastroller when using flush-mode="manual, I'm using hibernate as provider, but I'm using the JPA EntityManager so that means that seam wraps it in ManagedPersistenceContext not ManagedHibernateSession (if that has anything to do with it)

                  
                  14:48:02,390 INFO [STDOUT] Hibernate:
                   insert
                   into
                   FDDB.SPECIES
                   (distribution, ecology, FDDB_COMMON_NAME, genetics, habitat, IMAGE_ID, metabolism, morphology, PUBLISHED_STATUS, SPECIAL_FEATURES, SPECIES2000_LSID, TAXA_ID, version, RECORD_ID)
                   values
                   (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
                  14:48:02,390 INFO [STDOUT] Hibernate:
                   insert
                   into
                   FDDB.ENTITY_VERSION_LOG
                   (changeLog, committer, timestamp, id)
                   values
                   (?, ?, ?, ?)
                  14:48:02,390 INFO [STDOUT] Hibernate:
                   insert
                   into
                   FDDB.SPECIES_versions
                   (VERSION_REVISION_TYPE, distribution, ecology, FDDB_COMMON_NAME, genetics, habitat, IMAGE_ID, metabolism, morphology, PUBLISHED_STATUS, SPECIAL_FEATURES, SPECIES2000_LSID, TAXA_ID, version, RECORD_ID, VERSION_REVISION)
                   values
                   (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
                  14:48:02,453 INFO [CachedConnectionManager] Closing a connection for you. Please close them yourself: org.jboss.resource.adapter.jdbc.jdk5.WrappedConnectionJDK5@9cafe0
                  java.lang.Throwable: STACKTRACE
                   at org.jboss.resource.connectionmanager.CachedConnectionManager.registerConnection(CachedConnectionManager.java:290)
                   at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:423)
                   at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:849)
                   at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:89)
                   at org.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:92)
                   at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
                   at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
                   at org.hibernate.jdbc.BorrowedConnectionProxy.invoke(BorrowedConnectionProxy.java:74)
                   at $Proxy147.prepareStatement(Unknown Source)
                   at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:534)
                   at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:116)
                   at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:109)
                   at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:244)
                   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2252)
                   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2688)
                   at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79)
                   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
                   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
                   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
                   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
                   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
                   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
                   at org.jboss.envers.synchronization.VersionsSync.beforeCompletion(VersionsSync.java:128)
                   at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:114)
                   at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:247)
                   at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:86)
                   at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
                   at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1389)
                   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:603)
                   at org.jboss.seam.jsf.SeamPhaseListener.handleTransactionsAfterPhase(SeamPhaseListener.java:341)
                   at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:241)
                   at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:192)
                   at com.sun.faces.lifecycle.Phase.handleAfterPhase(Phase.java:175)
                   at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:114)
                   at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
                   at com.icesoft.faces.webapp.http.core.JsfLifecycleExecutor.apply(JsfLifecycleExecutor.java:17)
                   at com.icesoft.faces.webapp.http.core.ReceiveSendUpdates.renderCycle(ReceiveSendUpdates.java:54)
                   at com.icesoft.faces.webapp.http.core.ReceiveSendUpdates.service(ReceiveSendUpdates.java:42)
                   at com.icesoft.faces.webapp.http.core.ViewBoundServer.service(ViewBoundServer.java:65)
                   at com.icesoft.faces.webapp.http.core.RequestVerifier.service(RequestVerifier.java:44)
                   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:63)
                   at com.icesoft.faces.webapp.http.servlet.MainSessionBoundServlet.service(MainSessionBoundServlet.java:139)
                   at com.icesoft.faces.webapp.http.servlet.SessionDispatcher.service(SessionDispatcher.java:53)
                   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:82)
                   at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
                   at com.icesoft.faces.webapp.xmlhttp.BlockingServlet.service(BlockingServlet.java:46)
                   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                   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.web.LoggingFilter.doFilter(LoggingFilter.java:58)
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                   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:45)
                   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: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:182)
                   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
                   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
                   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                   at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
                   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
                   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
                   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
                   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
                   at java.lang.Thread.run(Unknown Source)
                  
                  


                  It's actually a problem because the connection is no longer managed after the call to entityManager.flush();

                  15:05:40,281 ERROR [JDBCExceptionReporter] Connection is not associated with a managed connection.org.jboss.resource.adapter.jdbc.jdk5.WrappedConnectionJDK5@9cafe0
                  ...
                  Caused by: java.sql.SQLException: Connection is not associated with a managed connection.org.jboss.resource.adapter.jdbc.jdk5.WrappedConnectionJDK5@9cafe0
                   at org.jboss.resource.adapter.jdbc.WrappedConnection.lock(WrappedConnection.java:81)
                   at org.jboss.resource.adapter.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:237)
                   at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:534)
                   at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:452)
                   at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161)
                   at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1573)
                   at org.hibernate.loader.Loader.doQuery(Loader.java:696)
                   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
                   at org.hibernate.loader.Loader.loadCollection(Loader.java:2015)
                   ... 107 more
                  


                  I'll try it with hibernateSession and see if it works.


                  Erik

                  • 6. Re: JBoss Seam and flushModel=manual
                    Adam Warski Master

                    Hello,

                    I just tested with 1.1.0.beta2 and Hibernate 3.3.1 and it works :)

                    So I suppose you have some other setup.

                    First of all, what do you have in components.xml? I have:

                     <persistence:managed-persistence-context
                    name="entityManager"
                    auto-create="true"
                    persistence-unit-jndi-name="java:/estEntityManagerFactory"/>
                    


                    Then, I inject the entity manager:
                    @In private EntityManager entityManager
                    


                    And I flush the entity manager in a long-running conversation which is started using
                    <begin-conversation join="true" flush-mode="manual"/>
                    


                    So what are your differences? :)

                    Adam

                    • 7. Re: JBoss Seam and flushModel=manual
                      Erik Bakstad Newbie

                      You are absolutely right, it works. I forgot to add jboss-web.xml to WEB-INF, so I was using an older version of hibernate.

                      Sorry for my stupid mistake :D

                      Thanks!
                      Erik

                      • 8. Re: JBoss Seam and flushModel=manual
                        Adam Warski Master

                        Heh, good that it's working :)

                        The mistake isn't stupid, but rather common and annoying - when I was setting up a Seam+Hibernate 3.3+Envers test yesterday, I did a very similar thing - forgot to update hibernate-validator and got weird MethodNotFound exceptions :).

                        Adam