【问题标题】:Spring data neo4j : findByPropertyValue returns null (even after indexing)Spring数据neo4j:findByPropertyValue返回null(即使在索引之后)
【发布时间】:2014-02-24 01:52:27
【问题描述】:

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

@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

    ..
    ..

}

在我的控制器类中,我注入了这样的 repo:

@Inject
private UserRepository userRepo;

我正在尝试使用以下内容检索用户对象:

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

我的图表中有 2 个用户,上面的对象检索对一个有效,但对另一个无效。如果我运行密码查询,我会看到两个节点。

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

感谢任何帮助。谢谢..

【问题讨论】:

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


    【解决方案1】:

    用户存储库还需要实现 NamedIndexRepository,因为您的索引已命名:

    public interface UserRepository extends NamedIndexRepository<User> {
    

    }

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-31
      • 1970-01-01
      • 1970-01-01
      • 2021-11-30
      • 2018-07-15
      • 1970-01-01
      相关资源
      最近更新 更多