通过@Repository 保存时出现 neo4j 空指针异常

neo4j null pointer exception while saving via @Repository

The sample project i'm working with can be found attached here - Spring Jira

这是我的配置

@EnableNeo4jRepositories(basePackages = "com.graph.repository")
public class DBConfig extends Neo4jConfiguration{
    @Value("${neo4j.location}")
    private String neo4jDatabaseLocation;

    @Override
    public SessionFactory getSessionFactory() {
        return new SessionFactory(getConfiguration(), "com.graph.entity");
    }

    @Bean
    public Configuration getConfiguration() {
        Configuration configuration = new Configuration();
        configuration.driverConfiguration()
            .setDriverClassName("org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver")
            .setURI(neo4jDatabaseLocation);
        return configuration;
    }

    @Bean
    @Override
    public Session getSession() throws Exception {
        return getSessionFactory().openSession();
    }
}

抽象实体

public abstract class Entity {
@GraphId
private Long id;

public Long getId() {
    return id;
}

@Override
public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || id == null || getClass() != o.getClass()) return false;

    Entity entity = (Entity) o;

    if (!id.equals(entity.id)) return false;

    return true;
}

@Override
public int hashCode() {
    return (id == null) ? -1 : id.hashCode();
}
}

这是我的实体

@NodeEntity(label = "Patient")
public class Patient extends Entity {
private String patientId;
private String patientName;
private String otherPatientId;
private String sex;
private String dateOfBirth;
private String patientIdIssuer;
@Relationship(type = "STUDY", direction = Relationship.UNDIRECTED)
private Set<Study> studies;

Getters and Setters...
}

研究有嵌套 entity/relationship 并且有另一个嵌套 entity/relationship。 1:N 关系

这是我的存储库

@Repository
public interface PatientRepository extends GraphRepository<Patient> {
}

这是调用方法

public class Test() {
    @Autowired
    private PatientRepository patientRepository;

    public void test() {
        Patient patient = new Patient();
        // set fields
        patientRepository.save(patient); -> This is where I get NPE
    }
}

堆栈跟踪:

Caused by: java.lang.NullPointerException: null
at org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver.nativeTransaction(EmbeddedDriver.java:180) ~[neo4j-ogm-embedded-driver-2.0.4.jar:na]
at org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver.newTransaction(EmbeddedDriver.java:148) ~[neo4j-ogm-embedded-driver-2.0.4.jar:na]
at org.neo4j.ogm.session.transaction.DefaultTransactionManager.openTransaction(DefaultTransactionManager.java:57) ~[neo4j-ogm-core-2.0.4.jar:na]
at org.neo4j.ogm.session.delegates.TransactionsDelegate.beginTransaction(TransactionsDelegate.java:37) ~[neo4j-ogm-core-2.0.4.jar:na]
at org.neo4j.ogm.session.Neo4jSession.beginTransaction(Neo4jSession.java:441) ~[neo4j-ogm-core-2.0.4.jar:na]
at org.neo4j.ogm.session.request.RequestExecutor.executeSave(RequestExecutor.java:84) ~[neo4j-ogm-core-2.0.4.jar:na]
at org.neo4j.ogm.session.delegates.SaveDelegate.save(SaveDelegate.java:75) ~[neo4j-ogm-core-2.0.4.jar:na]
at org.neo4j.ogm.session.delegates.SaveDelegate.save(SaveDelegate.java:44) ~[neo4j-ogm-core-2.0.4.jar:na]
at org.neo4j.ogm.session.Neo4jSession.save(Neo4jSession.java:425) ~[neo4j-ogm-core-2.0.4.jar:na]

有人可以告诉我我做错了什么吗??

注意:我之前使用 sdn.3.x 使用 GraphDatabaseService

进行了此操作

看起来唯一缺少的是 Neo4jConfiguration class 上的 @Configuration 注释:

@org.springframework.context.annotation.Configuration
@EnableTransactionManagement
@EnableNeo4jRepositories(basePackages = "com.seyfert.matrix.graph.repository")
public class DBConfig extends Neo4jConfiguration{
...