[英]spring-data-neo4j PropertyReferenceException when creating custom repository
[英]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.