1 Reply Latest reply on Jul 11, 2002 11:38 AM by Dain Sundstrom

    oops - CMR in JBoss 3.0.1RC1

    James Compton Newbie

      We have CMR issues when trying to get a collection of local objects and convert them into value objects within the entity bean. Code and ejb-jar.xml at the bottom.
      The exception thrown is:
      2002-07-11 09:46:57,198 ERROR [org.jboss.ejb.plugins.LogInterceptor] Transaction
      RolledbackException, causedBy:
      java.lang.IllegalStateException: A CMR collection may only be used within the transction in which it was created


      We had this working in previous releases. We are also not using commit option A in our jboss.xml.

      Code: (the relationship between User and Role is M-M and is unidirectional - coming from User)
      public User getUser()
      {
      User user = new User();
      user.setUserId(this.getUserId());
      user.setUsername(this.getUsername());
      user.setPassword(this.getPassword());
      user.setFirstname(this.getFirstname());
      user.setSurname(this.getSurname());
      user.setSuspended(this.getSuspended());
      user.setCompanyName(this.getCompanyName());
      user.setValidated(this.getValidated());
      user.setAddress(this.getAddress().getAddress());
      user.setRoles(collectionToVO(this.getRoles()));
      return user;
      }

      public Collection collectionToVO(Collection a_colLocal)
      {
      Vector vecVO = new Vector();
      Iterator iterator = a_colLocal.iterator();
      while (iterator.hasNext())
      {
      RoleLocal local = (RoleLocal)iterator.next();
      vecVO.add(local.getRole());
      }

      return vecVO;
      }

      ejb-jar.xml (relationship)
      <ejb-relation>

      <ejb-relation-name>User-has-many-Roles</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>UserBean UNIDIRECTIONAL</ejb-relationship-role-name>
      Many
      <relationship-role-source>
      <ejb-name>UserBean</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>roles</cmr-field-name>
      <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>UNIDIRECTIONAL UserBean</ejb-relationship-role-name>
      Many
      <relationship-role-source>
      <ejb-name>RoleBean</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>
      </ejb-relation>
      <ejb-relation>

        • 1. Re: oops - CMR in JBoss 3.0.1RC1
          Dain Sundstrom Master

          Does getUser() and collectionToVO(Collection a_colLocal) use the transaction attribute Required?

          Basicaly, I am asking if these two methods use the same transaction, because the spec requirement of cmr collection usage.

          If they are in the same transaction, try the cvs Branch_3_0 code (there was a bug in this code and commit option A). If it is still broken, post a bug report at SourceForge along with a small test case.