繁体   English   中英

spring-data-neo4j findByPropertyValue方法始终返回null?

[英]spring-data-neo4j findByPropertyValue method always return null?

我有社交模型:

import java.util.Set;

import org.neo4j.graphdb.Direction;
import org.springframework.data.neo4j.annotation.Fetch;
import org.springframework.data.neo4j.annotation.GraphId;
import org.springframework.data.neo4j.annotation.Indexed;
import org.springframework.data.neo4j.annotation.NodeEntity;
import org.springframework.data.neo4j.annotation.RelatedTo;

@NodeEntity
public class Social {
    @GraphId
    private Long id;

    @Indexed
    private Long userId;

    @RelatedTo(type="FRIEND", direction=Direction.BOTH)
    @Fetch private Set<Social> friends;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public Set<Social> getFriends() {
        return friends;
    }

    public void setFriends(Set<Social> friends) {
        this.friends = friends;
    }

    public void addFriend(Social social){
        this.friends.add(social);
    }
}

和存储库:

import org.springframework.data.neo4j.repository.GraphRepository;
import org.springframework.data.neo4j.repository.RelationshipOperationsRepository;

import com.msci.travelpad.entities.Social;

public interface SocialRepository extends GraphRepository<Social>, RelationshipOperationsRepository<Social> {

}

但是当我想使用userID通过userId查找社交节点时:

public Social findByUserId(Long userId) {
    return socialRepository.findByPropertyValue("userId", userId);
}

findByUserId始终返回null。

在此处输入图片说明

您是否尝试在存储库中实现自己的find方法,例如:

Iterable<Social> findByUserId(Long userId);

索引是否正确创建(请参阅Spring Data for Neo4j使用GraphRepository返回Null )?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM