7 Replies Latest reply on Sep 17, 2004 10:31 AM by kabirkhan

    Problems with container managed transaction and cmr

    balteo

      Hello,

      1. I have a jsp which calls a stateless session facade
      2. My stateless session facade itelf calls a findbyprimarykey finder of an entity bean
      3. My entity bean has a collection of another entity bean
      4. I use dto to transfer data over the tiers

      I tried many combinations of trans attributes to no avail.

      I get the following error again and again:

      java.lang.IllegalStateException: A CMR collection may only be used within the transction in which it was created
       org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet.getIdList(RelationSet.java:66)
       org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet.access$000(RelationSet.java:32)
       org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet$1.<init>(RelationSet.java:355)
       org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet.iterator(RelationSet.java:353)
       org.apache.taglibs.standard.tag.common.core.ForEachSupport.toForEachIterator(Unknown Source)
       org.apache.taglibs.standard.tag.common.core.ForEachSupport.supportedTypeForEachIterator(Unknown Source)
       org.apache.taglibs.standard.tag.common.core.ForEachSupport.prepare(Unknown Source)
       javax.servlet.jsp.jstl.core.LoopTagSupport.doStartTag(Unknown Source)
       org.apache.jsp.displayItem_jsp._jspx_meth_c_forEach_0(displayItem_jsp.java:282)
       org.apache.jsp.displayItem_jsp._jspx_meth_f_view_0(displayItem_jsp.java:157)
       org.apache.jsp.displayItem_jsp._jspService(displayItem_jsp.java:97)
       org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
       javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
       org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
       org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
       org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
       javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
       com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
       com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)
       com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
       com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
       com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
       javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
      


      All the sources for the ejb tier can be viewed here:

      http://www.parispano.com/test_guide/ejb_tier/src/com/softwareag/test_guide/

      I have been stuck on this for over two weeks and would accept any comments and suggestions.

      Thanks in advance,

      Julien Martin.

        • 1. Re: Problems with container managed transaction and cmr
          kabirkhan

          I couldn't find any deployment descriptors...

          As a starting point, you shouldn't be able to go wrong if you use container managed transactions for your session beans and trans-attribute=Required for all of your EJB's.

          • 2. Problems with container managed transaction and cmr
            balteo

            Thanks Kabkhan,
            The DDs are here :
            http://www.parispano.com/test_guide/ejb_tier/etc/
            I tried required for all ejbs I still get the same error...
            Any idea?
            Julien.

            • 3. Re: Problems with container managed transaction and cmr
              balteo

              Hello kabkhan,
              Me again. I received several replies advising me the same thing as you advised: setting everything at required. I am almost positive I tried that already and it didn't work. I am going to try again. Do you think this could be a bug with Jboss 4 rc1?
              Julien.

              • 4. Problems with container managed transaction and cmr
                balteo

                Me again,
                Just a doubt. Is the following the way to set trans attributes?

                - <assembly-descriptor>
                - <container-transaction>
                - <method>
                 <ejb-name>PGSessionFacadeEJB</ejb-name>
                 <method-name>*</method-name>
                 </method>
                 <trans-attribute>Required</trans-attribute>
                 </container-transaction>
                - <container-transaction>
                - <method>
                 <ejb-name>EstablishmentEJB</ejb-name>
                 <method-name>*</method-name>
                 </method>
                 <trans-attribute>Required</trans-attribute>
                 </container-transaction>
                - <container-transaction>
                - <method>
                 <ejb-name>GradeEJB</ejb-name>
                 <method-name>*</method-name>
                 </method>
                 <trans-attribute>Required</trans-attribute>
                 </container-transaction>
                - <container-transaction>
                - <method>
                 <ejb-name>VisitorCommentEJB</ejb-name>
                 <method-name>*</method-name>
                 </method>
                 <trans-attribute>Required</trans-attribute>
                 </container-transaction>
                - <container-transaction>
                - <method>
                 <ejb-name>CountryEJB</ejb-name>
                 <method-name>*</method-name>
                 </method>
                 <trans-attribute>Required</trans-attribute>
                 </container-transaction>
                - <container-transaction>
                - <method>
                 <ejb-name>CategoryEJB</ejb-name>
                 <method-name>*</method-name>
                 </method>
                 <trans-attribute>Required</trans-attribute>
                 </container-transaction>
                 </assembly-descriptor>
                


                Thanks in advance,

                Julien Martin.

                • 5. Re: Problems with container managed transaction and cmr
                  kabirkhan

                  That is the right way to set them required, yes. The attributes in the DD from your link are pretty crazy, But as you say you have been fiddling :-)

                  Make sure there is container-transaction entry for every bean - PGSearchEngineValueListHandlerEJB does not appear to have one...

                  • 6. Problems with container managed transaction and cmr
                    balteo

                    Hello Kabkhan,
                    I just modified my DD and set everything to required as well as downloaded jboss 4 rc2 and I still get the same error. Is this a bug in jboss? I doubt it... Then where is the problem? Have you got any idea?
                    Thanks in advance,
                    Julien.

                    • 7. Re: Problems with container managed transaction and cmr
                      kabirkhan

                      Aha!

                      java.lang.IllegalStateException: A CMR collection may only be used within the transction in which it was created
                       org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet.getIdList(RelationSet.java:66)
                       org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet.access$000(RelationSet.java:32)
                       org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet$1.<init>(RelationSet.java:355)
                       org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet.iterator(RelationSet.java:353)
                       org.apache.taglibs.standard.tag.common.core.ForEachSupport.toForEachIterator(Unknown Source)
                       org.apache.taglibs.standard.tag.common.core.ForEachSupport.supportedTypeForEachIterator(Unknown Source)
                       org.apache.taglibs.standard.tag.common.core.ForEachSupport.prepare(Unknown Source)
                       javax.servlet.jsp.jstl.core.LoopTagSupport.doStartTag(Unknown Source)
                       org.apache.jsp.displayItem_jsp._jspx_meth_c_forEach_0(displayItem_jsp.java:28


                      From what you say in your original post and from this stack trace, I think what you are doing is:

                      jsp calls session bean
                      ===Tx Starts===
                      Session Bean calls Entity.findByPK()
                      SessionBean returns entity
                      ===TX ends====
                      jsp tries to iterate over the CMR collection of the entity bean (and is not in the Tx.


                      The usage pattern for what you are trying to achieve is

                      jsp calls session bean
                      ===Tx Starts===
                      Session Bean calls Entity.findByPK()
                      SessionBean iterates over CMR Collection and populates DTO object
                      Session Bean returns DTO
                      ===TX ends====
                      jsp uses DTO

                      The DTO is just for holding data to be passed across the layers, and knows nothing about ejb's