4 Replies Latest reply on Dec 20, 2007 4:58 PM by asookazian

    implementing SMPC questions

    asookazian

      So I'm trying to replace the EntityManager that is injected into my SFSB via @PersistenceContext with a SMPC (Seam Managed Persistence Context) as follows:

      import org.jboss.seam.annotations.In;
      import javax.persistence.EntityManager;
      
      @In(create=true)
      EntityManager em; //a Seam-managed persistence context

      1) I'm still getting "@In attribute requires non-null value: securityAuditAction.em" when I run my test case even after adding the create=true element setting in the @In attribute. How can I fix that?

      2) The previous code was as follows:

      @PersistenceContext(unitName="boIcomsSecurityAudit", type=PersistenceContextType.EXTENDED)
      private EntityManager em;


      Note that I have multiple persistence units in my persistence.xml as well as multiple datasources in my *-ds.xml. How will the SMPC know which datasource or persistence unit to use? The optional elements for @In are required, create, scope, value.

      3) The reason I'm converting to SMPC to begin with is due to the premature update that was happening in my use case (still don't know exactly where/why but think it may be flushMode=auto [default] related). I read section 8.3.3 of the Seam and O/R mapping section of the docs and it sounds like this SMPC strategy will fix my problem (i.e. manual flush at end of conversation only).

      4) is the SMPC similar to JPA EXTENDED persistence context type in that the JPA entities are not released (unmanaged) from the PC?

        • 1. Re: implementing SMPC questions
          asookazian

          When you use the following flushMode element:

          @Begin(flushMode=FlushModeType.MANUAL)


          must you use SMPC or can you use JPA Extended PersistenceContext as follows?

          @PersistenceContext(unitName="boIcomsSecurityAudit", type=PersistenceContextType.EXTENDED)
           private EntityManager em;


          • 2. Re: implementing SMPC questions
            pmuir

             

            "asookazian" wrote:
            1) I'm still getting "@In attribute requires non-null value: securityAuditAction.em" when I run my test case even after adding the create=true element setting in the @In attribute. How can I fix that?


            What does your components.xml look like?

            2) The previous code was as follows:

            @PersistenceContext(unitName="boIcomsSecurityAudit", type=PersistenceContextType.EXTENDED)
            private EntityManager em;


            Note that I have multiple persistence units in my persistence.xml as well as multiple datasources in my *-ds.xml. How will the SMPC know which datasource or persistence unit to use? The optional elements for @In are required, create, scope, value.


            By the wiring in your components.xml

            4) is the SMPC similar to JPA EXTENDED persistence context type in that the JPA entities are not released (unmanaged) from the PC?


            It's like an Extended PC that is scoped to a conversation rather than a SFSB. It has significantly simpler propagation rules

            must you use SMPC or can you use JPA Extended PersistenceContext as follows?


            You can use either, but you must use Hibernate atm.

            • 3. Re: implementing SMPC questions
              asookazian

              I got the following exception after successfully integrating SMPC and flushMode=MANUAL to my code. Any idea why it's happening?

              13:52:47,413 INFO [SecurityAuditAction] in preDestroy
              13:52:47,429 ERROR [STDERR] Dec 20, 2007 1:52:47 PM javax.faces.event.MethodExpressionActionListener processAction
              SEVERE: Received 'javax.ejb.EJBTransactionRolledbackException' when invoking action listener '#{securityAuditAction.submit}' for component 'submitEmployee'
              13:52:47,429 ERROR [STDERR] Dec 20, 2007 1:52:47 PM javax.faces.event.MethodExpressionActionListener processAction
              SEVERE: javax.ejb.EJBTransactionRolledbackException: org.hibernate.PersistentObjectException: detached entity passed to persist: com.cox.beans.entity.TblSecurityAuditNote
               at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:87)
               at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
               at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
               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:83)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
               at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:106)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
               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:204)
               at org.jboss.ejb3.stateful.StatefulLocalProxy.invoke(StatefulLocalProxy.java:100)
               at $Proxy113.submit(Unknown Source)
               at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
               at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
               at java.lang.reflect.Method.invoke(Unknown Source)
               at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
               at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
               at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
               at org.jboss.seam.ejb.RemoveInterceptor.aroundInvoke(RemoveInterceptor.java:41)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
               at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:106)
               at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
               at org.javassist.tmp.java.lang.Object_$$_javassist_2.submit(Object_$$_javassist_2.java)
               at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
               at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
               at java.lang.reflect.Method.invoke(Unknown Source)
               at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:328)
               at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:341)
               at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
               at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
               at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
               at org.jboss.seam.el.OptionalParameterMethodExpression.invoke(OptionalParameterMethodExpression.java:45)
               at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
               at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:88)
               at javax.faces.event.ActionEvent.processListener(ActionEvent.java:77)
               at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:746)
               at javax.faces.component.UICommand.broadcast(UICommand.java:368)
               at javax.faces.component.UIData.broadcast(UIData.java:854)
               at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:184)
               at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:162)
               at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:350)
               at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java: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(ApplicationFilterChain.java:290)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
               at jcifs.http.NtlmHttpFilter.doFilter(NtlmHttpFilter.java:118)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
               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.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.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
               at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
               at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
               at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
               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.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:179)
               at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java: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(CachedConnectionValve.java:157)
               at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
               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(Http11Protocol.java:580)
               at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
               at java.lang.Thread.run(Unknown Source)
              Caused by: javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: com.cox.beans.entity.TblSecurityAuditNote
               at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerIm
              13:52:47,429 ERROR [STDERR] pl.java:629)
               at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:218)
               at org.jboss.seam.persistence.EntityManagerProxy.persist(EntityManagerProxy.java:135)
               at com.cox.beans.session.SecurityAuditAction.submit(SecurityAuditAction.java:293)
               at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
               at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
               at java.lang.reflect.Method.invoke(Unknown Source)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
               at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
               at com.cox.beans.interceptor.ProfilingInterceptor.profile(ProfilingInterceptor.java:23)
               at sun.reflect.GeneratedMethodAccessor147.invoke(Unknown Source)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
               at java.lang.reflect.Method.invoke(Unknown Source)
               at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
               at com.cox.beans.interceptor.LoggerInterceptor.profile(LoggerInterceptor.java:19)
               at sun.reflect.GeneratedMethodAccessor146.invoke(Unknown Source)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
               at java.lang.reflect.Method.invoke(Unknown Source)
               at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
               at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
               at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:46)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
               at org.jboss.seam.persistence.ManagedEntityIdentityInterceptor.aroundInvoke(ManagedEntityIdentityInterceptor.java:48)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
               at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
               at org.jboss.seam.core.ConversationInterceptor.aroundInvoke(ConversationInterceptor.java:56)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
               at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
               at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:26)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
               at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:27)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
               at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:106)
               at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
               at sun.reflect.GeneratedMethodAccessor145.invoke(Unknown Source)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
               at java.lang.reflect.Method.invoke(Unknown Source)
               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.invokeInCallerTx(TxPolicy.java:126)
               ... 92 more
              Caused by: org.hibernate.PersistentObjectException: detached entity passed to persist: com.cox.beans.entity.TblSecurityAuditNote
               at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:79)
               at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
               at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:618)
               at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:592)
               at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:596)
               at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:212)
               ... 141 more


              • 4. Re: implementing SMPC questions
                asookazian

                submit method in SFSB:

                @End
                 @TransactionAttribute(TransactionAttributeType.REQUIRED) //REQUIRED is default, but added for clarity
                 public void submit() {
                
                 Object[] myAuditListSelection = getMyAuditListSelection();
                
                 TblSecurityAuditWorking tsaw = (TblSecurityAuditWorking)myAuditListSelection[1];
                
                 //determine what status to assign to each row/employee based on answers to radio buttons...
                
                 //RULES: if yes/yes/yes --> green
                 // if any no(s) --> yellow
                 // if none selected --> red
                
                 Boolean icomsAccountApproved = tsaw.getIcomsAccountApproved()==null?false:tsaw.getIcomsAccountApproved();
                 Boolean adjustmentLimitApproved = tsaw.getAdjustmentLimitApproved()==null?false:tsaw.getAdjustmentLimitApproved();
                 Boolean securityLevelApproved = tsaw.getSecurityLevelApproved()==null?false:tsaw.getSecurityLevelApproved();
                
                 if ( icomsAccountApproved && adjustmentLimitApproved && securityLevelApproved ) {
                 //green
                 tsaw.setAuditProgress(SecurityAuditConstants.AUDIT_COMPLETE);
                 }
                 else if ( !icomsAccountApproved || !adjustmentLimitApproved || !securityLevelApproved ) {
                 //yellow
                 tsaw.setAuditProgress(SecurityAuditConstants.AUDIT_WAITING_ICOMS);
                 }
                 else {
                 //yellow
                 tsaw.setAuditProgress(SecurityAuditConstants.AUDIT_WAITING_ICOMS);
                 }
                
                 emICOMS.merge(tsaw);
                
                 //check to see if there are any notes for each radio button for this employee/row
                 //then update/insert accordingly
                
                 //TO DO: move the hard-coding 3 for # of updateable columns in dataTable to resource bundle
                
                 // TO DO: noteAction.submit() was moved to action listener attribute in modalPanels...
                 //call submit to ensure new note is added to array
                 //noteAction.submit();
                
                 for (int i = 0; i < 3; i++) {
                 TblSecurityAuditNote note = getTblSecurityAuditNote(currentRowNum, i);
                 if (note != null) {
                 log.info("myNotes["+currentRowNum+"]["+i+"]: noteText = " + note.getNoteText());
                 emICOMS.persist(note);
                 }
                 }
                
                 emICOMS.flush();
                
                 }