|
|
|
|
Strumenti |
21-12-2021, 17:21 | #1 |
Member
Iscritto dal: Nov 2020
Messaggi: 75
|
[JAVA,NEO4J] L'oggetto Result ritorna una List<Record> vuota
Buonasera a tutti,
ho scritto una query cypher per il database neo4j per grafi Codice:
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 ecco il risultato Codice:
{ "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" } } Codice:
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; } - size list 0 - list is empty - result has no next record Come è possibile che con il programma java non restituisca nessun Record invece se eseguito in "Neo4j browser" cioè la shell per connettersi al database a grafo restituisce il Record voluto? E' lo stesso db, stessa query. Ho notato pero' che qualsiasi query come questa restituisce sempre lista vuota: MATCH (b:Book) RETURN b LIMIT 5; |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 00:37.