0 Replies Latest reply on Feb 12, 2003 11:31 AM by java_whacko

    IllegalStateException when accessing a CMR

    java_whacko

      I am getting the following exception when accessing a one - many CMR in a session bean:
      java.lang.IllegalStateException: A CMR collection may only be used wit
      hin the transction in which it was created
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet.getIdList
      (RelationSet.java:58)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet.iterator(
      RelationSet.java:260)
      at com.centric.intranet.ejb.session.impl.UserServiceBean.getUs
      erAndContactDetails(UserServiceBean.java:135)
      at java.lang.reflect.Method.invoke(Native Method)
      at org.jboss.ejb.StatelessSessionContainer$ContainerIntercepto
      r.invoke(StatelessSessionContainer.java:660)
      at org.jboss.resource.connectionmanager.CachedConnectionInterc
      eptor.invoke(CachedConnectionInterceptor.java:186)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(Abst
      ractTxInterceptor.java:107)
      at org.jboss.ejb.plugins.AbstractTxInterceptorBMT.invokeNext(A
      bstractTxInterceptorBMT.java:144)
      at org.jboss.ejb.plugins.TxInterceptorBMT.invoke(TxInterceptor
      BMT.java:62)
      at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.i

      I have a UserEJB and PhoneEJB and a user can have many phones. I have a getUserAndContactDetails method in a stateless session bean where I get the user ejb and then get the telephones. Here is the code snippet:
      User user = CentricIntranetUtils.getUserHome().findByUserName(aUserId);

      Iterator mIter = user.getTelephones().iterator();
      log.debug("Telephones Retrieved");
      if(user.getTelephones() != null && user.getTelephones().size() > 0)
      {
      Vector phones = new Vector();
      while(mIter.hasNext())
      {
      Phone mPhone = (Phone) mIter.next();
      PhoneNumberValue mPhoneVal = mPhone.getPhoneDetails();
      phones.addElement(mPhoneVal);
      }
      mUser.setTelephones(phones);
      }

      I have read all the previous messages regarding this problem and set the transaction attributes correctly in ejb-jar.xml.
      <assembly-descriptor>
      <container-transaction>

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


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


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


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

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>

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

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      </assembly-descriptor>

      I tried with starting a user transaction and retrieving the telephones within the tranx and it works fine. I dont understand why the session bean's method is not included in a transaction even though the transaction attribute is set to Required.

      Any help is appreciated.

      Thanks