0

我有社交模式:

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 找到社交节点时:

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

findByUserId 始终返回 null。

在此处输入图像描述

4

1 回答 1

0

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

Iterable<Social> findByUserId(Long userId);

是否正确创建了索引(请参阅Null return using GraphRepository from Spring Data for Neo4j)?

于 2013-08-23T15:27:37.680 回答