I tried to write a tree application. I wrote a NodeEJB. A Node can have m children (Nodes) and one parent (also Node).
My problem is that I create the parent. In the next Step I try to create a child with the following code in the ejbPostCreate method of NodeBean:
LocalNode parent = localNodeHome.findByPrimaryKey( parentId );
LocalNode child = localNodeHome.findByPrimaryKey( id ); // this
Collection c = parent.getChildren( );
c.add( child );
parent.setChildren( c );
child.setParent( parent );
And I always get a NullPointerException because getChildren() returns null. Next Step I tried is
to check with an if clause if I get a null pointer and than I created a new Vector. But than I got a ClassCastException.
I have no idea what kind of class I should use for the collection. I attach the relation from the ejb-jar.xml.
Thanks for for help.
<ejb-relation-name>node - node</ejb-relation-name>
I've found the error. I have switched the "Many" and "One" multiplicity in the ejb-jar.xml