Good Morning,
I wrote a cypher query:
MATCH (b:Book)
WITH max(b.ide) AS maximum
MATCH (b:Book)
WHERE b.ide = maximum
RETURN b
ORDER BY ID(b) DESC
LIMIT 1
This query returns first max record from Book records.
{
"identity": 23,
"labels": [
"Book"
],
"properties": {
"name": "L'archivio di Agostino Rocca",
"about": "Rocca, Agostino - Archivio - Inventari",
"inLanguage": "it",
"bookFormat": "EPUB",
"ide": 100,
"id": "https://www.fondazioneeinaudi.it/library?id=1c3cfa82-39ed-4d19-9177-a5df3fe77cc4",
"type": "http://schema.org/Book"
}
}
instead if I execute my java program List is empty from Result object.
public int getMaxResult(){
Driver driver = GraphDatabase.driver( "bolt://localhost:11003",
AuthTokens.basic( "neo4j",
"Admpa" ) );
Session session = driver.session(SessionConfig.forDatabase( "eindb" ));
Transaction transaction = session.beginTransaction();
nodeMaxQuery = "MATCH (b:Book) ";
nodeMaxQuery += "WITH max(b.ide) AS maximum ";
nodeMaxQuery += "MATCH (b:Book) ";
nodeMaxQuery += "WHERE b.ide = maximum ";
nodeMaxQuery += "RETURN b ";
nodeMaxQuery += "ORDER BY ID(b) DESC ";
nodeMaxQuery += "LIMIT 1 ";
Result res = transaction.run(nodeMaxQuery);
if(res == null ) {
System.out.println("is null");
}
if(res.list().size() <= 0) {
System.out.println("size list is zero");
}else {
System.out.println("size list is " + res.list().size());
}
if(res.list().isEmpty()) {
System.out.println("list is empty");
}
if(!res.hasNext()) {
System.out.println("result has no next record. ");
}
List<Record> resList = res.list();
System.out.println("list of records: " + resList);
int nodeBookId = 0;
for (Record record : resList) {
Value rec = record.get("b");
System.out.print("Record --> [");
for (String key : rec.keys()) {
System.out.print(key + " : " + rec.get(key) + ", ");
if(key == "ide") nodeBookId = rec.get(key).asInt() + 1;
}
System.out.println("]");
}
transaction.commit();
return nodeBookId;
}
program output is:
size list 0
list is empty
list has no next record
list
Why does result is empty list but in neo4j browser I get one record? Right it's one record.