5 Replies Latest reply on Jan 5, 2003 1:32 PM by Ignacio de Cordoba

    A CMR collection may only be used within the transction in w

    Ignacio de Cordoba Novice

      Hi there,
      in a JSP page I am getting the following error when I invoke a method in a Session bean which returns a collection directly returned by a CMR get in a Entity.

      HTTP ERROR: 500 A CMR collection may only be used within the transction in which it was created.

      This works in Pramati J2EE server but throws that exception in JBoss.

      Thanks for any help to address this.

      Ignacio

        • 1. Re: A CMR collection may only be used within the transction
          krypton Novice

          Hi Ignacio,

          I had the same issue a few months ago. I did resolve this issue, the error was a coding/config related one as far as i can remember. Here are some tips ( sorry must be the hangover from xmas + newyear still looming in my head ... )

          - Make sure the beans involved during the call/tx are added inside ejb-jar.xml including any session beans that proxy the call to the local entities etc .. ..ie.

          <assembly-descriptor>

          <container-transaction>

          <ejb-name>SomeBean</ejb-name>
          <method-name>*</method-name>


          <trans-attribute>Required</trans-attribute>
          ... etc

          Try that for now ...

          Regards

          K

          • 2. Re: A CMR collection may only be used within the transction
            Ignacio de Cordoba Novice

            Thanks a lot for your reply.
            I had tried that in other app, but my real problem here is that I am using the JBoss generated Collection in a JSP page, with the JSTL forEach tag... I try not to write java code in my jsp pages.
            Is there a transaction tag or a way to wrap JSP tags into a transaction?

            Thanks again.
            Ignacio

            • 3. Re: A CMR collection may only be used within the transction
              Ignacio de Cordoba Novice

              Sorry for my last post. I pasted the wrong test in the message.
              The thing is that I already had this code in my XMLs. It is true that I am going outside the transaction as I access the Collection from a JSP page in a iteration tag (forEach).
              My problem is how to wrap that tag into a transaction without using Java in the JSP page.

              Thanks for any help.

              • 4. Re: A CMR collection may only be used within the transction
                krypton Novice

                Hi IOcordoba,

                At least you are awake :-) Ok ...

                Separate your EJB access through a delegate like MarcRUTheEJBWizzDelegate .... such that you do the following ..

                public class AddressDelegate {

                /**
                * Log related
                */
                static Logger log = LoggerFactory.getLogger(AddressDelegate.class.getName());

                private AddressManagerHome addressManagerHome = null;
                private AddressManager addressManager = null;


                /**
                * Default class constructor.
                */
                public AddressDelegate() {

                if (log.isDebugEnabled()) {
                log.debug("Initialised AddressDelegate.");
                }

                init();
                }

                private void init() {

                try {
                addressManager = ProxyFactory.getAddressManagerHome().create();
                } catch (CreateException ce) {
                log.error("Failed to Initialise AddressDelegate. [CREATE]", ce);
                } catch (RemoteException re) {
                log.error("Failed to Initialise AddressDelegate. [REMOTE[", re);
                }

                }



                // --------------------------------------------------------
                // Find Addresses
                // --------------------------------------------------------
                public Set findAllAddresses() throws StudBookException {

                try {
                return addressManager.findAllAddresses();
                } catch(RemoteException re) {
                log.error("Failed call to proxy.");
                throw new StudBookException(re.getMessage());
                }
                }


                This is a standalone class that hides the ejb lookup etc. All related sub classes must be in the TX>

                Can you paste the code used where you locate the ejb etc and the tx props in the ejb-jar-xml ?

                • 5. Re: A CMR collection may only be used within the transction
                  Ignacio de Cordoba Novice

                  Thanks for your message. Here is the structure I am using. I am developing an administration for WEB components in a system to make som users be able to access some components. I have a Component EJB and a Role EJB, linked by CMR through an intermediate table.
                  I want to list the Roles of a particular component and that is why I use the forEach tag to iterato through the Component.getRoles() CMR method.
                  I use a javabean in the HTTP Session, so the JSP page doesn't directly reference the Session EJB that references the Component Local Entity EJB:

                  Jsp Page ( tag) -> JavaBean.get -> Session EJB -> Entity EJB


                  When I use forEach tag to iterate through a Collection findAll() in a Entity Home, everything goes ok, but when a iterate through a Collection getCMREJBs(), I get the error.
                  As I see in your code, you use a javabean to reference the Session EJB (Manager) that references the EJB Home. In findAll() methods that return collection anyway, I have no problem. This only happens when getting CMR Collections.

                  What I guess I must find is a way to make all the JSP code (the forEach tag in particular) to belong to the same transaction that the javabean+SessionEJB(Manager)+LocalEntity.getCMRBEANS().

                  Right?