2 Replies Latest reply on Jul 17, 2002 12:09 PM by dsundstrom

    NullPointerException one-to-many relationship

    gixer

      Hi,

      JBoss throws a NullPointerException inside the container when I iterate a relationship managed "field".

      I have an entity bean which contains a one-to-many bidirectional relationship. The relationship is actually a relationship to itself (are you allowed to do this?).

      The problem:
      - The entity bean can be retrieved by its home-interface
      - The beans container manager relation Collection can also be retrieved.
      - It's even possible to call collection.size() and get a valid value.
      * But when I iterate through the Collection JBoss throws a NullPointerException.

      Please help me, what is wrong?

      Environment:
      Win2000, JBoss RC1, jdk1.4, EJB 2.0

      ...
      // local method..
      EJBChannel channel = ... // remote interface.
      Collection children = channel.getChildren(); // CMR-field (Works)
      logger.debug("Collection:" + children + " size:" + children.size()) ; // (Works)
      Iterator iter = children.iterator();
      while(iter.hasNext()) {
      logger.debug("Child:" + iter.next()); // NullPointerException
      }

      ...
      Bean class:
      public abstract class EJBChannelBean implements EntityBean {
      ...
      public abstract Collection getChildren();
      public abstract void setChildren(Collection c);
      ...
      }

      ejb-jar.xml
      ...
      <ejb-relation>
      <ejb-relation-name>One-channel-contains-many-children </ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Channel-has-Children</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>Channel</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>children</cmr-field-name>
      <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Channel-has-one-parent</ejb-relationship-role-name>
      Many
      <relationship-role-source>
      <ejb-name>Channel</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>parent</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>



      Exception:

      java.lang.NullPointerException
      at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.getEntityEJBLocalObject(BaseLocalContainerInvoker.java:223)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet$1.next(RelationSet.java:272)
      at se.cybercom.pwf.ejb.navigation.EJBNavigationManagerBean.initiateChildren(EJBNavigationManagerBean.java:101)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:653)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:147)
      at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:77


        • 1. Re: NullPointerException one-to-many relationship
          bgannur

          Hi

          I too experiencing the same problem as u have faced.

          If you got any solution can u please send it to me.

          Thanks

          Brahma



          • 2. Re: NullPointerException one-to-many relationship
            dsundstrom

            Do both entities have a local interface delcared in the ejb-jar.xml file?

            The EJB spec requires that both sides have a declared local interface if the relationship is bidirectional:

            An entity bean that does not have a local interface can have only unidirectional relationships from itself to other entity beans. The lack of a local interface prevents other entity beans from having a relationship to it.

            If that is not the problem, try the 3.0.1 release. If that does not work, please post a bug report along with a small testcase at sourceforge.