Re: [Neo4j] Neo4j - Issues with retrieving nodes by index

16 views
Skip to first unread message

Michael Hunger

unread,
Nov 18, 2012, 9:35:23 AM11/18/12
to ne...@googlegroups.com
Did you do

Tx.success()

AND

tx.finish()

When creating the db?

Sent from mobile device

Am 18.11.2012 um 06:08 schrieb Salini <sasidhar...@gmail.com>:

Hi All,

I have an existing neo4j database and i have created an index named "idIndex"(when i created the database). I am connecting to the existing database and  trying to retrieve a node using the getSingle() function in the following way, but none of the nodes are being able to be retrieved.  However, when i tried to retrieve the nodes in the same transaction, where i created the database, i was able to retrieve.

Here is my code
//I assume this will open the existing database
graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
registerShutdownHook
(graphDb)  ;
 
Transaction tx = graphDb.beginTx();
       
try{
            //it says the index exists
           
boolean  exists = graphDb.index().existsForNodes("idIndex");

           
if(exists)
               
System.out.println("Index exists");
            //I assume this gives the handle to the existing index
           
Index<Node> idIndex = graphDb.index().forNodes("idIndex");
             //retrieve the node by key and value
             
Node NodeA = idIndex.get("name","54O").getSingle();
           
Node NodeB = idIndex.get("name","32I").getSingle();
           }
         finally
            {
                tx.finish();
            }


Could anyone please help me to understand what is going wrong here?

Thanks,
Salini S

--
 
 
Reply all
Reply to author
Forward
0 new messages