2017-06-17 85 views
0

,當我遇到了問題,同時實現在春數據的Neo4j自定義庫。我有一個節點實體Competence。下面是這個類彈簧數據的Neo4j PropertyReferenceException創建自定義庫

@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

你沒有一個叫'country'在'Competence'類屬性。命名約定必須適合spring數據。使用適當的屬性名稱而不是不存在的屬性。 – harshavmb

+0

我想創建我自己的'findByCountry()'實現,它將執行一個查詢,我將在這個方法中構造。但是,如果我使用現有的屬性,我會得到一個默認的實現。 –

回答

0

在有你的能力類的國家屬性。你仍然可以覆蓋JPA的findByCountry利用彈簧提供@Query註釋提供的默認實現。