我是Java,Neo4j和Spring Data的新手,我遇到了后者的一些困难。
我目前正在使用Spring Data Neo4j 4.1.6。我有一个基本类Person,用@NodeEntity标记。它有无参数构造函数和一个带有String名称的构造函数,仅用于测试。
在经历了很多错误后,我设法达到了这个目的,我有一个Neo4jTemplate。 问题是当我尝试在数据库中保存类Person的对象时,我得到一个警告,即这些不是可持久类的实例。
e.g。 WARN org.neo4j.ogm.session.Neo4jSession - 线程1:xtractor.Person不是可持久类的实例
以下是配置类和提前致谢。
package xtractor;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.ogm.session.Session;
import org.neo4j.ogm.session.SessionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.config.Neo4jConfiguration;
import org.springframework.data.neo4j.template.Neo4jOperations;
import org.springframework.data.neo4j.template.Neo4jTemplate;
@Configuration
public class Neo4jConfig extends Neo4jConfiguration{
@Bean
public org.neo4j.ogm.config.Configuration getConfiguration() {
org.neo4j.ogm.config.Configuration config =
new org.neo4j.ogm.config.Configuration();
config.driverConfiguration().
setDriverClassName("org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver")
.setURI("file:///" + Console.dbLocation + ".db");
return config;
}
@Override
@Bean
public SessionFactory getSessionFactory() {
// with domain entity base package(s)
return new SessionFactory(getConfiguration(), "xtractor.*");//tried everything here
}
@Bean(destroyMethod = "shutdown")
public GraphDatabaseService graphDatabaseService() {
return Console.db; //thats the DatabaseService I use.
}
@Bean
//@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public Session getSession() throws Exception{
return super.getSession();
}
@Bean
public Neo4jOperations neo4jTemplate() throws Exception{
return new Neo4jTemplate(getSession());
}
}
编辑:Person.class 我认为问题是我无法对这些@NodeEntities进行Neo4j扫描
package xtractor;
import org.neo4j.ogm.annotation.*;
@NodeEntity
public class Person {
@GraphId
private Long graphId;
private String firstName;
private String lastName;
private int birthdate;
private String birthplace;
public Person(){
}
public Person(String firstName){
this.firstName = firstName;
System.out.println("Person created");
}
//getters and setters
}