I'm using an embedded database, creating a graph of people who have sent messages to one another. I can see that createRelationshipTo gets called, but then I can't find the relationship later.
I get a set of relationships outgoing from user A, but it keeps re-inserting the relationship to user B, the test (highlighted below) never comes back as true.
Thanks.
Node recipNode = findUser(recip);
if (recipNode == null) {
// user does not exist in graph, add them.
recipNode = createAndIndexUser(recip);
}
// we have both nodes, check for a relationship between
// them
Relationship rel = null;
for (Relationship r : userNode.getRelationships(
Direction.OUTGOING, RelTypes.SENT_TO)) {
if (recipNode == r.getOtherNode(userNode)) {
rel = r;
break;
}
}
Transaction tx = graphDb.beginTx();
try {
if (rel == null) {
// didn't find a relationship, add it
rel = userNode.createRelationshipTo(recipNode,
RelTypes.SENT_TO);
rel.setProperty(COUNT_KEY, 1);
} else {
// found one, just increment.
Integer count = (Integer) rel
.getProperty(COUNT_KEY);
count++;
rel.setProperty(COUNT_KEY, count);
}
tx.success();