Spring数据neo4j:findByPropertyValue返回null(即使在索引之后)

时间:2014-02-24 01:52:27

标签: neo4j spring-data spring-data-neo4j

我有一个用户节点类,如下所示:

@NodeEntity
public class User {

    @GraphId 
    Long nodeId;

    @Indexed(unique = true,indexName="uid")
    Long uid;

    String name;

    @RelatedTo(type="FRIENDS", direction=Direction.BOTH)
    Set<User> friends;

    @RelatedToVia(type="FRIENDS", elementClass=IsFriends.class)
    Set<IsFriends> friendRelationships;

    @RelatedTo(type="LIKES", direction=Direction.OUTGOING)
    Set<Article> article;

    @RelatedToVia(type="LIKES", elementClass=Reco.class)
    Set<Likes> likeRelationships;

    //getters and setters

    ..
    ..

}

在我的控制器类中,我已经注入了这样的回购:

@Inject
private UserRepository userRepo;

我正在尝试使用以下方法检索User对象:

User user = userRepo.findByPropertyValue("uid", userId);

我的图表中有2个用户,上面的对象检索适用于一个,但另一个则失败。如果我运行cypher查询,我确实看到了两个节点。

这两个节点都是使用Spring Data Neo4j创建的。

感谢任何帮助。感谢..

1 个答案:

答案 0 :(得分:0)

用户存储库还需要实现 NamedIndexRepository&lt;&gt; ,因为您的索引名为:

public interface UserRepository extends NamedIndexRepository<User> {

}

然后搜索包括索引的名称:

User user = userRepo.findByPropertyValue("uid","uid", userId);