[Neo] relationship.getOtherNode(localnode) returning null?
Peter Neubauer
peter.neubauer at jayway.se
Wed Jun 27 08:49:21 CEST 2007
Well,
two problems here. First the code givign me null is this:
public int cmdLs(Dictionary opts, Reader in, PrintWriter out,
Session session) {
TransactionUtil.beginTx();
Node localnode = currentNode;
String[] ids = (String[]) opts.get("id");
if(ids.length == 1)
{
localnode = neo.getNodeById(Long.parseLong(ids[0]));
}
Iterable<Relationship> relationships =
localnode.getRelationships(Direction.OUTGOING);
for (Relationship relationship : relationships) {
out.println(localnode.getId() + "--->" +
nodeToString(relationship.getOtherNode(localnode)));
}
Iterable<Relationship> incomingRelationships =
currentNode.getRelationships(Direction.OUTGOING);
for (Relationship relationship : incomingRelationships) {
out.println(localnode.getId() + "<---" +
nodeToString(relationship.getOtherNode(localnode)));
}
TransactionUtil.finishTx(true, true);
return 0;
}
Throwing a null into nodeToString(Node).
Secondly, Direction.OUTGOING gives med the same nodes as
Direction.INCOMING. Is that intended and is it relevant at all, in
that case, should it be removed?
/peter
On 6/21/07, Johan Svensson <johan at neopersistence.com> wrote:
> On 6/21/07, Emil Eifrem <emil at neopersistence.com> wrote:
> >
> > On 6/20/07, Peter Neubauer <peter.neubauer at jayway.se> wrote:
> > > Hi there,
> > > not sure this is trivial but relationship.getOtherNode(localnode) is
> > > giving me null in some cases. Can this occur and what is the reason
> > > for it?
> >
> > This should not happen. The API specs at
> >
> >
> > http://api.neo4j.org/1.0-b5/org/neo4j/api/core/Relationship.html#getOtherNode(org.neo4j.api.core.Node)
> >
> > is very clear that the only thing that can be returned is the start or
> > end node of the relationship, or a runtime exception if the client
> > passes in a node that's not connected to either end of the
> > relationship. It should never return null.
> >
> > So it's a bug. Not sure when the current implementation can
> > (erroneously) return null. Johan may be able to shed some light on
> > that?
>
>
> The current implementation will return null if node passed in isn't
> connected to the relationship, so if node N1 and node N2 are connected via
> relationship R. R.getOtherNode( Nx ) will return null for all Nx except N1
> and N2. This will be changed to throw runtime exception instead.
>
> --
> Johan
> _______________________________________________
> Neo mailing list
> User at lists.neo4j.org
> http://lists.neo4j.org/mailman/listinfo/user
>
>
More information about the User
mailing list