繁体   English   中英

Spring-data-neo4j + @Query抛出PropertyReferenceException

[英]Spring-data-neo4j + @Query throws PropertyReferenceException

我的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 (attach)的第一部分映射到Domain类的属性。 我试图重命名该方法,但错误仍然出现。

配置:Sprind-Data-Neo4j版本3.1.1RELEASE,neo4j版本2.1.2

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM