Nodes are not reference-equals. You'll only get NodeProxy objects which are created on the fly in different operations.
But the equals()
-method does id-equality so you should use that.
n1.equals(n2)
or if you keep the node id around use
n1.getId() == n2.getId()