我正在使用Neo4j OGM 2.0.4驅動程序和Java(嵌入式驅動程序)。當我確實保存(項目)會話時,一切看起來都沒問題。 Hovewer當我想要加載從數據庫項目我得到這個異常:從OGM驅動程序加載Neo4j數據庫中的數據時出現NullPointerException
16:01:23.182 [main] INFO org.neo4j.ogm.service.DriverService - Using driver: org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver
16:01:24.768 [main] DEBUG org.neo4j.ogm.service.Components - Setting driver to: org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver
16:01:24.782 [main] WARN org.neo4j.ogm.session.Neo4jSession - Thread 1: neo4jCMS.entity.Author is not an instance of a persistable class
16:01:24.782 [main] WARN org.neo4j.ogm.session.Neo4jSession - Thread 1: neo4jCMS.entity.Author is not an instance of a persistable class
Saved
Exception in thread "main" java.lang.NullPointerException
at org.neo4j.ogm.MetaData.entityType(MetaData.java:280)
at org.neo4j.ogm.session.Neo4jSession.entityType(Neo4jSession.java:486)
at org.neo4j.ogm.session.delegates.LoadByTypeDelegate.loadAll(LoadByTypeDelegate.java:60)
at org.neo4j.ogm.session.delegates.LoadByTypeDelegate.loadAll(LoadByTypeDelegate.java:108)
at org.neo4j.ogm.session.Neo4jSession.loadAll(Neo4jSession.java:152)
at neo4jCMS.TestSite.run(TestSite.java:35)
at neo4jCMS.Application.main(Application.java:20)
在執行:
Author author1 = new Author("Author no 1");
Author author2 = new Author("Author no 2");
session.save(author1);
session.save(author2);
System.out.println("Saved");
Iterable<Author> authors = session.loadAll(Author.class);
for (Author author : authors)
{
System.out.println("Author: " + author.getName());
}
我的節點類:
@NodeEntity
public class Author
{
@GraphId
private Long id;
private String _name;
public Author() { _name = "";}
public Author(String name)
{
_name = name;
}
public String getName()
{
return _name;
}
}
你能否確認''作者'從session.loadAll(Author.class)返回;'不是'null' - 你的錯誤指向'NullPointerException'。 – ishmaelMakitla
@ishmaelMakitla堆棧跟蹤顯示在該方法內發生異常,而不是在它返回後發生。 – EJP