Re: Problems with fetching node from index in 1.8-SNAPSHOT

24 views
Skip to first unread message

moneyplantrb

unread,
Aug 14, 2012, 2:01:44 AM8/14/12
to ne...@googlegroups.com
Just checking on the status of this. Did anyone @Neo4J get a chance to check this out? Just a few lines of code that demonstrates the problem. Again, perhaps, there is something special we need to do within the code to make it work for 1.8-SNAPSHOT.


On Friday, August 10, 2012 10:06:53 AM UTC-7, moneyplantrb wrote:
Fetching node from index works well with 1.7:

<groupId>org.neo4j</groupId>
<artifactId>neo4j-rest-graphdb</artifactId>
<version>1.7</version>


However with 1.8-SNAPSHOT, it fails:

<groupId>org.neo4j</groupId>
<artifactId>neo4j-rest-graphdb</artifactId>
<version>1.8-SNAPSHOT</version>


I have uploaded the example to github:


This example tests:

  1. Adding a node to Neo4J (Works)
  2. Adding a simple property to a node. (Works)
  3. Creating an index in Neo4J (Works)
  4. Adding the node, property and value to the index. (Fails in 1.8-SNAPSHOT)

The step 4 does not seem to work in 1.8-SNAPSHOT of Neo4J. It does work in 1.7 of Neo4J.

Perhaps, we are doing something wrong. Or some new code needs to be written to make this code work?

Also, submitted this code to Build Doctor, and Peter Neubauer for review via twitter.

Following environment information where it is tested:

Darwin Kernel Version 11.4.0 (Mac), JDK 1.6.0_33-b03-424-11M3720


Michael Hunger

unread,
Aug 14, 2012, 2:28:57 AM8/14/12
to ne...@googlegroups.com
Hi sorry for the delay.

The behavior of "transactions" changed in 1.8, in 1.7 they were no-op, i.e. just ignored. So you could just leave them off to not confuse people.

In 1.8 it tries to collect all operations within a tx as a batch-operation which will then be executed on the server.

This has the implication that the results retrieved within that "tx" are not immediately available but only after you called tx.success and tx.finish

So changing your code to this works (I added tx.success() which was missing and moved the getSingle() (as you would also size() to after the "tx" when the data is actually available.

HTH

Michael

        IndexHits<Node> nodeFromIndex = null;
        tx = graphDb.beginTx();
        try {
            myIndex = graphDb.index().forNodes(indexName);
            nodeFromIndex = myIndex.get( key, value );
            tx.success();
        } finally {
            tx.finish();
        }
        System.out.println( "firstNode from index = " + nodeFromIndex.getSingle() );

Michael Hunger

unread,
Aug 14, 2012, 2:58:10 AM8/14/12
to ne...@googlegroups.com
I also updated the readme to make it clearer: please check and review:

moneyplantrb

unread,
Aug 14, 2012, 5:04:00 PM8/14/12
to ne...@googlegroups.com
Okay, I tried this fix, and works as documented by you. I would think the create new transaction requirement should
be for index/node updates and not when we fetch from an index. So that is why, when I did a myIndex.add(), I expected
that one to be wrapped up in a separate transaction from the remaining code. I did not expect that the lines:

myIndex = graphDb.index().forNodes(indexName);
pNodeHits = myIndex.get(key, value);

need to be in it's own transaction. 

Thanks for spending the time explaining about transactions.
I have made the fix in the github package I posted to this thread, in case anyone would like to know what fix actually
worked for me.
Reply all
Reply to author
Forward
0 new messages