3 Replies Latest reply on Mar 23, 2006 5:26 PM by jelevy01

    CMR collections access from web-tier

    zak4899

      Hi,

      I've set up a straightfroward one-to-many CMR relationship with two
      Entity Beans on JBoss 4 (XDoclet declarations at the end of this post).
      Calling the CMR method getAddenda() that returns the Set works
      perfectly from another bean, but I would like to call it from custom
      JSP tags in the web tier of the same server. When I try this, I get the
      following exception:
      A CMR collection may only be used within the transction in which it was
      created

      What do I have to do to call this method from the web tier? A sample
      would be great.
      Could you point me to documentation explaining this CMR restriction?


      Thanks,
      blu


      In bean Project:
      /**
      * @ejb.interface-method
      *
      * @ejb.relation
      * name="Project-Addenda"
      * role-name="Project-has-many-Addenda"
      * target-ejb="Addendum"
      * target-role-name="Addendum-belongs-to-Project"
      */
      public abstract Set getAddenda();


      In bean Addendum:
      /**
      * @ejb.interface-method
      *
      * @ejb.relation
      * name="Project-Addenda"
      * role-name="Addendum-belongs-to-Project"
      * target-ejb="Project"
      * target-role-name="Project-has-many-Addenda"
      * cascade-delete="yes"
      *
      * @jboss.relation
      * related-pk-field="planKey"
      * fk-column="plan_key"
      * fk-constraint="false"
      */
      public abstract ProjectLocal getProject();



        • 1. Re: CMR collections access from web-tier
          redbeard15

          i'm not sure how you're exactly accessing the various beans n methods, but you mention something that will point to the solution:


          Calling the CMR method getAddenda() that returns the Set works
          perfectly from another bean, but I would like to call it from custom
          JSP tags in the web tier of the same server. When I try this, I get the
          following exception:

          The act of instantiating a collection of related objects and then retrieving the value objects from that collection must be done in the same transaction.

          I suspect that when you call the 'getAddenda()' method from another bean, the methods on that bean require a transaction. You can check your configuration for this.

          However, I'm not sure, but I suspect that servlets (e.g., JSP pages) do not wrap entire methods in a transaction. You'll have to do this yourself.

          I was running into the same sort of problem running JunitEE tests. I had to augment my JunitEE tests with something like the following (code example not complete):
          Context ic = new InitialContext();
          tx = (UserTransaction) ic.lookup ("java:comp/UserTransaction");
          tx.begin();
          
          AccountLocal lObj = home.findByPrimaryKey(objKey);
          AccountValue vObj = lObj.getAccountValue();
          tx.commit();
          

          this is because I had created value objects for another bean (1:n) related to Account. sooo, the 'getAccountValue()' method also retrieves value objects for the Account children, all in one method call.

          • 2. Re: CMR collections access from web-tier

            RB,

            Thank you for your reply, except that I haven't deployed my application yet :(.

            I am just tring to get JBoss up w/o exceptions.

            J

            • 3. Re: CMR collections access from web-tier

              Ignore above, wrong thread.