我在 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
这里有什么问题?
答案 0 :(得分:0)
在您的Competence类中拥有country属性。您仍然可以使用spring提供的@Query注释覆盖JPA为findByCountry提供的默认实现。