[Neo] Node identity
johan at neotechnology.com
Wed Jul 2 18:51:06 CEST 2008
On Wed, Jul 2, 2008 at 4:48 PM, Peter Haensgen <P.Haensgen at intershop.de> wrote:
>> > Are there any reasons for comparing nodes by their id and not use
> a node can be identified by its id. So you can compare two nodes like:
> if (aNode.getId() == bNode.getId()) ...
> Node is only an interface. The actual instance that you get has a
> different class (some proxy). From my observations it is not guaranteed
> that you always get the same node proxy object when you access the same
> node, e.g. if aNode and bNode represent the same node in the database,
> aNode.getId() == bNode.getId() --> true, but
> aNode == bNode --> very likely false
> The proxy class that implements the Node interface therefore should
> override the equals() method and compare the ids instead. I don't know
> if that has been done, but I would think so.
Yes. All implementations of Node or Relationship interfaces have
equals overridden. So always compare using id or equals method. Never
use object reference compare since they may be different (this is true
for relationship types too).
More information about the User