Reputation: 175
I have a strange problem when I'm trying execute a cypher query in an java application. The result.dumpToString()- method shows me the correct result. But when I'm trying to iterate, the last node is always missing (for every executed query):
for (Map<String, Object> row : result) {
System.out.println(((Node) row.get("A")));
System.out.println(((Node) row.get("A")).getProperty("name").toString());
}
The first output is correct. I see all nodes of the result. In the second output one node is missing, although I know, that the node has a "name"-property.
Has someone an idea? Thank you
Upvotes: 1
Views: 116
Reputation: 175
Solved my problem: I was executing the query without beginning a Transaction. Now it works. Nevertheless this is a strange behaviour.
Thank you all
Upvotes: 0
Reputation: 18022
If you're missing a second output, it's likely that the value of that property is a string that is blank. This line:
System.out.println(((Node) row.get("A")).getProperty("name").toString());
In the presence of an attribute "name" that is blank, this will print nothing at all (but a linefeed).
Also, the way you're doing this is a bit dangerous; keep in mind that in general nodes can be missing, so getProperty("name")
can return null. Meaning that when you call toString()
on it, you can end up with a NullPointerException
. It's better to maybe write either this:
row.get("A").getProperty("name", "missing").toString();
That will return "missing" if the property is missing, or:
Object propValue = row.get("A").getProperty("name");
if(propValue != null)
System.out.println(propValue.toString());
else System.out.println("Missing name property");
Upvotes: 2