Can't find relationships that are added.

17 views
Skip to first unread message

betseyb

unread,
Feb 6, 2013, 2:55:54 PM2/6/13
to ne...@googlegroups.com
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.

The relevant snippet is as follows:

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.
Have i missed something utterly obvious?

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();

Michael Hunger

unread,
Feb 6, 2013, 3:15:21 PM2/6/13
to ne...@googlegroups.com
You forgot to call tx.finish() it is a two step process.

tx.success() tx.failure() just mark the tx and tx.finish() does the actual commit.

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

betseyb

unread,
Feb 6, 2013, 3:23:42 PM2/6/13
to ne...@googlegroups.com
Actually, I do, I just neglected to copy and paste.  It's in a finally block.

Michael Hunger

unread,
Feb 6, 2013, 3:26:11 PM2/6/13
to ne...@googlegroups.com
Then you should find them again.

Can you publish the full code as a project on github or else where with a failing test?
Thanks

michael

Betsey Benagh

unread,
Feb 6, 2013, 3:33:52 PM2/6/13
to ne...@googlegroups.com
I agree that I shoudl find them, but I don't.  That's why I asked the question.  I was pretty sure I was doing everything correctly.

Unfortunately, I can't publish the whole project.  It's integrated with something much bigger, and gets its input from proprietary data sources. It would take a week that I don't have to refactor it into a toy project.

What I can do is post the corrected code.  I appreciate any insight anyone might have, including ways to debug.

Thanks,

betsey

} finally {
tx.finish();
}

betseyb

unread,
Feb 6, 2013, 3:39:47 PM2/6/13
to ne...@googlegroups.com
I don't mean to seem ungrateful or a jerk, and I apologize if my response read that way.  I'm extremely frustrated, doubly so because this only runs in a remote lab that I have limited access to.

I truly appreciate any pointers or help that anyone can offer.


Michael Hunger

unread,
Feb 6, 2013, 4:15:32 PM2/6/13
to ne...@googlegroups.com
You should be able to run it on your local machine too.
There are no special requirements.

Cheers

Michael

(neo4j.org) <-[:WORKS_ON]- (@mesirii) -[:TAKES_CARE_OF]-> (you) -[:WORKS_WITH]->(@Neo4j)




Am 06.02.2013 um 21:39 schrieb betseyb:

I don't mean to seem ungrateful or a jerk, and I apologize if my response read that way.  I'm extremely frustrated, doubly so because this only runs in a remote lab that I have limited access to.

I truly appreciate any pointers or help that anyone can offer.



Michael Hunger

unread,
Feb 6, 2013, 4:18:23 PM2/6/13
to ne...@googlegroups.com
Where is the place where you "don't find" the node or rel again?
Some notes inline:

please add some log output so that you see what happens

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)) {
// use equals here
Reply all
Reply to author
Forward
0 new messages