【问题标题】:Spring-data-neo4j + @Query throws PropertyReferenceExceptionSpring-data-neo4j + @Query 抛出 PropertyReferenceException
【发布时间】:2014-07-25 13:24:21
【问题描述】:

我的Domain 类有以下存储库:

public interface IDomainRepository extends GraphRepository<Domain>, RelationshipOperationsRepository<Domain>{
    //cause of error
    @Query("MATCH n WHERE id(n) = {0} SET n :{1}")
    public void attachLabel(Long id, String label);

}

来自GraphManager(使用IDomainRepository 的服务)我正在调用attachLabel,如下所示:

@Transactional
    public void attachLabel(Domain domain, String label){
        domainRepository.attachLabel(domain.getId(), label);
    }

这是我的测试用例,用于attachLabel 方法:

@Test
    public void attachLabelSuccess(){

        Domain domain = new Domain();
        domain.setName(UUID.randomUUID().toString());
        domain.setDescription("xyz");

        domain = graphManager.create(domain);
        graphManager.attachLabel(domain, "DummyLabel");

        Domain d1 = domainRepository.findOne(domain.getId());

        //Should have [Domain, DummyLabel]
        Assert.assertEquals(2, d1.getLabels().size());
    }

我得到以下异常,当我运行测试时它在加载 ApplicationContext 时失败:

Caused by: org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'IDomainRepository': 
Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: 
No property attach found for type Domain!
...
Caused by: org.springframework.data.mapping.PropertyReferenceException: 
No property attach found for type Domain!
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:75)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:327)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:359)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:307)
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:270)
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:241)

似乎 SDN 试图将attachLabel(附加)的第一部分映射到Domain 类的属性。我已经尝试重命名该方法,但仍然出现错误。

配置:Sprint-Data-Neo4j 版本 3.1.1.RELEASE,neo4j 版本 2.1.2。

已修复 问题是,我不小心使用了来自 mongodb 命名空间的 @Query 注释而不是 od neo4j。

【问题讨论】:

    标签: java spring neo4j spring-data-neo4j


    【解决方案1】:

    您无法在 Cypher 中使用参数更新标签。不幸的是,这是不可能的。

    因此,您必须构建查询并通过 neo4jTemplate 运行它。

    【讨论】:

    • 是的,我注意到了,并且已经按照您建议的方式解决了这个问题。我还注意到有用于管理标签的 @Labels 注释(已计划)。什么时候支持?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 2021-06-20
    • 2021-03-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多