![](/img/trans.png)
[英]Spring-data-neo4j + @Query throws PropertyReferenceException
[英]spring-data-neo4j PropertyReferenceException when creating custom repository
在Spring Data Neo4J中實現自定義存儲庫時遇到問題。 我有一個節點實體Competence
。 這是此類的代碼
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
@NodeEntity
public class Competence extends AbstractGraphElement {
/** ID of the competence */
@GraphId
private Long id;
/** Competence's short name */
private String name;
/** Code of the competence */
private String code;
/** Description of the competence */
private String text;
/** Level of the competence */
private int level;
private int minAge;
private int maxAge;
/** Corresponding node's x coordinate */
private Float x;
/** Corresponding node's y coordinate */
private Float y;
@Relationship(type = "REQUIRES", direction = Relationship.OUTGOING)
private List<Requirement> requirements = new ArrayList<>();
// ... Getters and Setters
}
我有CompetenceRepository
擴展GraphRepository<Competence>
和定制CurriculumRepository
@RepositoryRestResource(collectionResourceRel = "competences", path = "competences")
public interface CompetenceRepository extends GraphRepository<Competence>, CurriculumRepository {
Competence findByName(@Param("name") String name);
Competence findById(@Param("id") Integer id);
Collection<Competence> findByNameLike(@Param("name") String name);
Collection<Competence> findAllByGraphId(@Param("graphId") UUID graphId);
Collection<Competence> findAll();
@Query("match (a:Curriculum) where ID(a) = {id} with a MATCH (c:Competence)-[:IS_PART_OF*]->(a) RETURN c")
Collection<Competence> findByCountry(@Param("id") Long id);
@Query("MATCH (c:Competence) WHERE ID(c) IN {ids} with c match p = (c)-[*0..1]-(c2:Competence) where id(c2) in {ids} RETURN p, id(c)")
Collection<Competence> filterGraphByCountry(@Param("ids") List<Long> ids);
@Query("match (c:Competence) where c.code =~ {code} and toString(c.level) =~ {level} and toString(c.minAge) =~ {minAge} and toString(c.maxAge) =~ {maxAge} WITH c MATCH p=(c)-[*0..1]-(d:Competence) where d.code =~ {code} and toString(d.level) =~ {level} and toString(d.minAge) =~ {minAge} and toString(d.maxAge) =~ {maxAge} return p, id(c)")
Collection<Competence> findAllByCodeAndLevelAndMinAgeAndMaxAge(@Param("code") String code, @Param("level") String level,
@Param("minAge") String minAge, @Param("maxAge") String maxAge);
@Query("match(c1:Competence)-[r:REQUIRES]->(c2:Competence) return c1, r, c2 LIMIT {limit}"/* "match(n) return n" */)
Collection<Competence> graph(@Param("limit") int limit);
}
這是CurriculumRepository
public interface CurriculumRepository {
Collection<Competence> findByCountry(@Param("country") String country);
}
及其實現類CurriculumRepositoryImpl
public class CurriculumRepositoryImpl implements CurriculumRepository {
@Override
public Collection<Competence> findByCountry(String country) {
return null;
}
}
當我運行應用程序時,出現異常
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property country found for type Competence!
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:77) ~[spring-data-commons-1.13.1.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:329) ~[spring-data-commons-1.13.1.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:309) ~[spring-data-commons-1.13.1.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:272) ~[spring-data-commons-1.13.1.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:243) ~[spring-data-commons-1.13.1.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.Part.<init>(Part.java:76) ~[spring-data-commons-1.13.1.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:247) ~[spring-data-commons-1.13.1.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:398) ~[spring-data-commons-1.13.1.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:378) ~[spring-data-commons-1.13.1.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:89) ~[spring-data-commons-1.13.1.RELEASE.jar:na]
at org.springframework.data.neo4j.repository.query.derived.DerivedGraphRepositoryQuery.<init>(DerivedGraphRepositoryQuery.java:68) ~[spring-data-neo4j-4.2.1.RELEASE.jar:na]
at org.springframework.data.neo4j.repository.query.GraphQueryMethod.createQuery(GraphQueryMethod.java:106) ~[spring-data-neo4j-4.2.1.RELEASE.jar:na]
at org.springframework.data.neo4j.repository.query.GraphQueryLookupStrategy.resolveQuery(GraphQueryLookupStrategy.java:45) ~[spring-data-neo4j-4.2.1.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:436) ~[spring-data-commons-1.13.1.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:221) ~[spring-data-commons-1.13.1.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:277) ~[spring-data-commons-1.13.1.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:263) ~[spring-data-commons-1.13.1.RELEASE.jar:na]
at org.springframework.data.neo4j.repository.support.Neo4jRepositoryFactoryBean.afterPropertiesSet(Neo4jRepositoryFactoryBean.java:66) ~[spring-data-neo4j-4.2.1.RELEASE.jar:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
... 43 common frames omitted
這里可能有什么問題?
在您的能力課程中擁有國家/地區屬性。 您仍然可以使用spring提供的@Query注釋覆蓋JPA為findByCountry提供的默認實現。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.