4 Replies Latest reply on Feb 25, 2004 7:26 PM by peterhawkins

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

    icordoba

      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
          h2o_polo

          to wrap your code into UserTransaction your will need to the following:

          javax.transasction.UserTransaction ut = null;
          boolean bFailed = false;
          try {
          Context initCtx = new InitialContext();
          ut = (UserTransaction) initCtx.lookup("UserTransaction");
          ut.begin ();

          // ... do your stuff here ...

          } catch (Exception e) {
          bFailed = true;
          // ... do your exception handling
          } finally {
          // commit or rollback your transaction
          if (bFailed) {
          try { ut.rollback (); } catch (Exception e0) {}
          } else {
          try { ut.commit (); } catch (Exception e0) {}
          }
          }

          Alex.

          • 2. Re: A CMR collection may only be used within the transction
            h2o_polo

            to wrap your code into UserTransaction your will need to the following:

            javax.transasction.UserTransaction ut = null;
            boolean bFailed = false;
            try {
            Context initCtx = new InitialContext();
            ut = (UserTransaction) initCtx.lookup("UserTransaction");
            ut.begin ();

            // ... do your stuff here ...

            } catch (Exception e) {
            bFailed = true;
            // ... do your exception handling
            } finally {
            // commit or rollback your transaction
            if (bFailed) {
            try { ut.rollback (); } catch (Exception e0) {}
            } else {
            try { ut.commit (); } catch (Exception e0) {}
            }
            }

            Alex.

            • 3. Re: A CMR collection may only be used within the transction
              icordoba

              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.

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

                "I try not to write java code in my jsp pages"? Bahaha! Tags are for fags.

                :0