neo4j-contrib / java-rest-binding

Java Bindings for the Neo4J Server REST API, providing an implementation of GraphDatabaseService
Other
120 stars 72 forks source link

Unique Factory NPE in batch transaction #35

Open adsgreen opened 11 years ago

adsgreen commented 11 years ago

The example in the Neo4j docs won't work due to NPE: http://docs.neo4j.org/chunked/milestone/transactions-unique-nodes.html

public Node getOrCreateUserWithUniqueFactory(String username, GraphDatabaseService graphDb ){    
    UniqueFactory<Node> factory = new UniqueFactory.UniqueNodeFactory(     graphDb, "users" )    {        
        @Override        
        protected void initialize( Node created, Map<String, Object> properties )        {  
    created.setProperty( "name", properties.get( "name" ) );        
        }    
    };     
    return factory.getOrCreate( "name", username );
}

The issue is at the factory.getOrCreate throws a NPE if Batch Transactions are enabled: Exception in thread "main" java.lang.NullPointerException at org.neo4j.rest.graphdb.index.SimpleIndexHits.getSingle(SimpleIndexHits.java:67) at org.neo4j.rest.graphdb.index.SimpleIndexHits.getSingle(SimpleIndexHits.java:37) at org.neo4j.graphdb.index.UniqueFactory.getOrCreate(UniqueFactory.java:197)

The problem is due to I think:

    public T getSingle() {
        Iterator<Object> it = hits.iterator();
        return it.hasNext() ? transform(it.next()) : null;
    }

"hits" is null causing the error.