I ran into problem while implementing a custom repository in Spring Data Neo4J . I have a node entity Competence
. Here is code of this class
@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
}
And I have CompetenceRepository
that extends GraphRepository<Competence>
and custom 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);
}
Here is CurriculumRepository
public interface CurriculumRepository {
Collection<Competence> findByCountry(@Param("country") String country);
}
And its implementation class CurriculumRepositoryImpl
public class CurriculumRepositoryImpl implements CurriculumRepository {
@Override
public Collection<Competence> findByCountry(String country) {
return null;
}
}
When I run the application I get the exception
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
What can be a problem here?
Have country property in your Competence class. you can still override the default implementation provided by JPA for findByCountry using @Query annotation provided by spring.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.