Hi all
Hi all

Thanks in advance for the attention and any suggestions. I hope my 
explanation of the issue is clear enough.

As noted in the subject line, I'm upgrading my java based project to 
Version 3 of the embedded API.  Unfortunately, I'm getting the following 
error:

SEVERE: exception in hasNext: The statement has been closed.

Code is below, but here's the explanation. In order to provide a layer of 
isolation in between my application code and the database code (in this 
case Neo4j), I'm using the DAO pattern. I'm assigning the ResourceIterator 
I'm getting back from the findNodes call to a variable in the user level 
iterator I'm defining. According to this page 
(https://neo4j.com/docs/java-reference/current/javadocs/org/neo4j/graphdb/Transaction.html)
 

"All ResourceIterables 
<https://neo4j.com/docs/java-reference/current/javadocs/org/neo4j/graphdb/ResourceIterable.html>
 that 
where returned from operations executed inside a transaction will be 
automatically closed when the transaction is committed or rolled back. Note 
however, that the ResourceIterator 
<https://neo4j.com/docs/java-reference/current/javadocs/org/neo4j/graphdb/ResourceIterator.html>
 should 
be closed 
<https://neo4j.com/docs/java-reference/current/javadocs/org/neo4j/graphdb/ResourceIterator.html#close-->
 as 
soon as possible if you don't intend to exhaust the iterator"

That's clear enough and seems to explain why I am getting the exception. 
 But there has to be some way to return an iterator for later use. At least 
I hope so.  The other choice that comes to mind would be to store all of 
the nodes in user memory so my user level interface can iterate through 
them, and that would be a bit problematic. I'll note that this code (which 
used to use the GlobalGraphOperations class) worked in Neo4j 2. but maybe 
that was a bug in Neo4j 2? Note that I have tried not closing the 
transaction (or even using a transaction at all). 

Any ideas?


Here's the actual source of the problem: It's in my definition of an 
iterator for the user visible structure representing nodes.

      public boolean hasNext() {
           // Wrap the neo4j iterator
           boolean hasN = false;
           GraphDatabaseService theDB = Neo4jDAOFactory.getTheNetworkDB();
           Transaction tx = theDB.beginTx();
           try {
              hasN = nodeIterator.hasNext();
           } catch (Exception e) {
               // should send this back using the message logs eventually
               this.logger.log (Level.SEVERE, "exception in hasNext: " + 
e.getMessage(), e);
           } finally {
               tx.close();
           }
           return hasN;
       }

But it doesn't make sense without also looking at:

    public Iterator<NetworkNodeTransferObject>
        getNetworkNodes(String nameSpace, String key, Object value){

        Neo4jNetworkNodeDAOIterator theIterator = null;
        GraphDatabaseService theDB = Neo4jDAOFactory.getTheNetworkDB();
        Transaction tx = theDB.beginTx();
        try {

            Label newLabel = Label.label(nameSpace);
            Iterator<Node> neo4jNodeList = theDB.findNodes(newLabel, key, 
value);
            theIterator = new Neo4jNetworkNodeDAOIterator();
            theIterator.nodeIterator = neo4jNodeList;
        } catch (Exception e) {
            // should send this back using the message logs eventually
            this.logger.log (Level.SEVERE, "exception in getNetworkNodes: " 
+ e.getMessage(), e);
        } finally {
            tx.close();
        }

        return theIterator;
    }

Thanks
Howard

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to