我正在使用带有Java(嵌入式驱动程序)的Neo4j OGM 2.0.4驱动程序。当我在会话中保存(项目)时,一切看起来都很好。 Hovewer当我想从数据库加载项目时我得到了这个例外:
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;
}
}
答案 0 :(得分:2)
首先,您需要在import string
import random
def target ():
a = random.choice(string.digits)
b = random.choice(string.digits)
c = random.choice(string.digits)
if a == b or a == c or c ==b or a == b == c:
target(targt())
else:
return str(a + b + c)
类中添加一个无参数构造函数,以便OGM创建对象。
如果没有解决,请尝试再次重新运行loadAll代码段。我在第一次执行时看到了奇怪的异常。我认为这是固定的,但可能只在Author
。
答案 1 :(得分:0)
问题在于配置。新的SessionFactory()没有参数&#34; myProject.subDirectory&#34;。添加后它可以正常工作。