NullPointerException one-to-many relationship
gixer Apr 27, 2002 12:30 PMHi,
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