[英]Spring-data-neo4j + @Query throws PropertyReferenceException
I have following repository for my Domain
class: 我的
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);
}
From GraphManager
(a service, which is using IDomainRepository) i'm calling attachLabel
as following: 从
GraphManager
(服务,正在使用IDomainRepository)中,我正在按以下方式调用attachLabel
:
@Transactional
public void attachLabel(Domain domain, String label){
domainRepository.attachLabel(domain.getId(), label);
}
And here is my test case, for attachLabel
method: 这是我的测试用例,用于
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());
}
I get the following exception, when I run the test it fails at loading ApplicationContext: 我收到以下异常,当我运行测试时,它在加载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)
Seems that SDN is somehow trying to map first part of attachLabel
(attach) to property of Domain
class. 似乎SDN正在以某种方式尝试将
attachLabel
(attach)的第一部分映射到Domain
类的属性。 I've tried to rename the method, but the error still appears. 我试图重命名该方法,但错误仍然出现。
Configuration: Sprind-Data-Neo4j version 3.1.1.RELEASE, neo4j version 2.1.2. 配置:Sprind-Data-Neo4j版本3.1.1RELEASE,neo4j版本2.1.2
FIXED The problem was, that I accidentally used @Query annotation from mongodb namespace instead od neo4j. 已修复问题是,我不小心使用了mongodb名称空间中的@Query注释,而不是od neo4j。
You can't update labels with parameters in Cypher. 您无法在Cypher中使用参数更新标签。 That's unfortunately not possible.
不幸的是,这是不可能的。
So you'd have to construct the query and run it via the neo4jTemplate. 因此,您必须构造查询并通过neo4jTemplate运行它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.