6 Replies Latest reply on Jan 23, 2009 5:54 PM by jkronegg

    what makes' no transaction is in progress'

    gringalet

      i want to update a database record during a stateful bean destorying.
      i have got these messages belows, who can giveme a hand?


      2008-06-24 14:03:05,937 DEBUG [org.jboss.seam.Component] instantiating Seam component: org.jboss.seam.core.events
      
      2008-06-24 14:03:05,937 DEBUG [org.jboss.seam.Component] initializing new instance of: org.jboss.seam.core.events
      
      2008-06-24 14:03:05,937 DEBUG [org.jboss.seam.Component] done initializing: org.jboss.seam.core.events
      
      2008-06-24 14:03:05,937 DEBUG [org.jboss.seam.core.Events] Processing event:org.jboss.seam.postRemoveVariable.visitCountEditor
      
      2008-06-24 14:03:05,937 DEBUG [org.jboss.seam.interceptors.RemoveInterceptor] Stateful component was removed: visitCountEditor
      
      2008-06-24 14:03:05,937 WARN  [org.jboss.seam.contexts.Contexts] Could not destroy component: visitCountEditor
      
      javax.ejb.EJBException: javax.persistence.TransactionRequiredException: no transaction is in progress
      
       at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:69)
      
       at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
      
       at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:197)
      
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
       at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
      
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
       at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:81)
      
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
       at org.jboss.ejb3.stateful.StatefulRemoveInterceptor.invoke(StatefulRemoveInterceptor.java:81)
      
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
       at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
      
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
       at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
      
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
       at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
      
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
       at org.jboss.ejb3.stateful.StatefulContainer.localInvoke(StatefulContainer.java:188)
      
       at org.jboss.ejb3.stateful.StatefulLocalProxy.invoke(StatefulLocalProxy.java:98)
      
       at $Proxy358.destroy(Unknown Source)
      
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      
       at java.lang.reflect.Method.invoke(Method.java:585)
      
       at org.jboss.seam.util.Reflections.invoke(Reflections.java:20)
      
       at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
      
       at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:72)
      
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:57)
      
       at org.jboss.seam.interceptors.RemoveInterceptor.aroundInvoke(RemoveInterceptor.java:40)
      
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
      
       at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:103)
      
       at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:50)
      
       at org.javassist.tmp.java.lang.Object_$$_javassist_26.destroy(Object_$$_javassist_26.java)
      
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      
       at java.lang.reflect.Method.invoke(Method.java:585)
      
       at org.jboss.seam.util.Reflections.invoke(Reflections.java:20)
      
       at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:123)
      
       at org.jboss.seam.Component.callComponentMethod(Component.java:1834)
      
       at org.jboss.seam.Component.callDestroyMethod(Component.java:1765)
      
       at org.jboss.seam.contexts.Contexts.destroy(Contexts.java:231)
      
       at org.jboss.seam.contexts.Lifecycle.destroyConversationContext(Lifecycle.java:535)
      
       at org.jboss.seam.contexts.Lifecycle.endSession(Lifecycle.java:288)
      
       at org.jboss.seam.servlet.SeamListener.sessionDestroyed(SeamListener.java:45)
      
       at org.apache.catalina.session.StandardSession.expire(StandardSession.java:687)
      
       at org.apache.catalina.session.StandardSession.isValid(StandardSession.java:579)
      
       at org.apache.catalina.session.ManagerBase.processExpires(ManagerBase.java:678)
      
       at org.apache.catalina.session.ManagerBase.backgroundProcess(ManagerBase.java:663)
      
       at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1284)
      
       at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1569)
      
       at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1578)
      
       at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1578)
      
       at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1558)
      
       at java.lang.Thread.run(Thread.java:595)
      
      Caused by: javax.persistence.TransactionRequiredException: no transaction is in progress
      
       at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:264)
      
       at org.jboss.seam.persistence.EntityManagerProxy.flush(EntityManagerProxy.java:83)
      
       at com.CMS.visitcount.VisitCountEditorBean.update(Unknown Source)
      
       at com.CMS.visitcount.VisitCountEditorBean.destroy(Unknown Source)
      
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      
       at java.lang.reflect.Method.invoke(Method.java:585)
      
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
      
       at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
      
       at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:37)
      
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:57)
      
       at org.jboss.seam.interceptors.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:47)
      
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
      
       at org.jboss.seam.interceptors.ManagedEntityIdentityInterceptor.aroundInvoke(ManagedEntityIdentityInterceptor.java:37)
      
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
      
       at org.jboss.seam.interceptors.ConversationInterceptor.aroundInvoke(ConversationInterceptor.java:63)
      
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
      
       at org.jboss.seam.interceptors.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:27)
      
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
      
       at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:103)
      
       at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:53)
      
       at sun.reflect.GeneratedMethodAccessor275.invoke(Unknown Source)
      
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      
       at java.lang.reflect.Method.invoke(Method.java:585)
      
       at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
      
       at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
      
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
       at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:57)
      
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
       at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
      
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
       at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
      
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
       at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
      
       ... 52 more
      
      2008-06-24 14:03:05,952 DEBUG [org.jboss.seam.contexts.Contexts] destroying: hotNewsRowList


      my code belows:


      
      @Name("visitCountEditor")
      
      @Stateful
      
      public class VisitCountEditorBean implements VisitCountEditor, Serializable {
      
       
      
       @In(create = true)
      
       private EntityManager entityManager;
      
       
      
       @Valid
      
       private VisitCount visitCount = new VisitCount();
      
       
      
       @Logger
      
       private static Log log;
      
       
      
       public VisitCount getInstance() {
      
        return visitCount;
      
       }
      
       
      
       public void setInstance(VisitCount instance) {
      
        this.visitCount = instance;
      
       }
      
       
      
       @Begin(join = true)
      
       public String create() {
      
        createVisitCount();
      
        Object sessionAttribute = null;
      
        FacesContext facesContext = FacesContext.getCurrentInstance();
      
        ExternalContext externalContext = facesContext.getExternalContext();
      
        Map sessionMap = externalContext.getSessionMap();
      
        log.info("visitcounteditor creat()");
      
        if (sessionMap != null)
      
         sessionAttribute = sessionMap.get("name");
      
        if (sessionAttribute == null) {
      
         // visitCountFinder.findVisitCounts()
      
       
      
         HttpServletRequest request = (HttpServletRequest) externalContext
      
           .getRequest();
      
       
      
         visitCount.setVisitCountIP(request.getRemoteAddr());
      
         DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
      
         Date date = new Date();
      
         String str = dateFormat.format(date);
      
       
      
         visitCount.setVisitCountStartTime(str);
      
         entityManager.persist(visitCount);
      
         sessionMap.put("name", visitCount);
      
        }
      
       
      
        return null;
      
       
      
       }
      
       
      
       public String createVisitCount() {
      
       
      
        visitCount = new VisitCount();
      
        return null;
      
       
      
       }
      
       
      
       public String update() {
      
       
      
        if (this.visitCount != null) {
      
         DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
      
         Date date = new Date();
      
         String str = dateFormat.format(date);
      
         this.visitCount.setVisitCountEndTime(str);
      
       
      
         entityManager.merge(visitCount);
      
         entityManager.flush();
      
       
      
        }
      
        return null;
      
       }
      
       
      
       @Destroy
      
       @Remove
      
       public void destroy() {
      
        update();
      
        System.out
      
          .println("---------------visit history created!---------------");
      
       }
      
       
      
       
      
      


        • 1. Re: what makes' no transaction is in progress'
          gringalet

          :( nobody knows what s reason?

          i want to make a counter that status how many people visit my website.
          in the firstpage, i insert a reord into database for visiter's ip address and begin-time when a stateful bean created. and i guess it s ok to put the update code for the end-time in the destory method of this stateful bean .
          can anyone give me more good advices? thanks
          :)

          • 2. Re: what makes' no transaction is in progress'
            dahm

            Hi,


            no it's not OK to put the update in the destroy() method. It's just as the error message says: At the time the destroy() method is called no transaction is active. Such methods are thought for cleanup operations such as releasing connections.


            What you could do is define a page action in xxx.page.xml that is being called every time the page is visited, i.e. your update() method.


            Cheers
               Markus

            • 3. Re: what makes' no transaction is in progress'
              harpritt

              Im sure i read that it was ok to update bean state in methods annoted with @Destroy....

              • 4. Re: what makes' no transaction is in progress'
                dahm

                Quote from the reference manual:



                Specifies that the method should be called when the context ends and its context variables are destroyed. Note that destroy methods are only supported for JavaBeans and stateful session beans.

                Destroy methods should be used only for cleanup. Seam catches, logs and swallows any exception that propagates out of a destroy method.

                If you think of the life cycle of a SFSB it doesn't make much sense to store data at that point of time anyway, since there's no garantuee when it will be called.

                • 5. Re: what makes' no transaction is in progress'
                  harpritt

                  Quoted from JBoss SEAM By Yaun and Heute RE the @Destroy annotation
                  Page 94, line 2




                  The method annotatde with @ destroy is invoked by Seam when the component is removed from the context(....). You can implement this method to handle component removal event (e.g.. to save the current bean state to a database at the timeout)


                  So now im confused!


                  DUDE!

                  • 6. Re: what makes' no transaction is in progress'
                    jkronegg

                    You should annotate your method with @Transactional to tell Seam to start a new transaction when calling it.