【问题标题】:spring-data-neo4j findByPropertyValue method always return null?spring-data-neo4j findByPropertyValue 方法总是返回 null?
【发布时间】:2013-08-23 14:06:33
【问题描述】:

我有社交模式:

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。

【问题讨论】:

  • 我运行您的代码没有任何问题。您需要在调用 findByUserId() 方法的位置发布代码。

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


【解决方案1】:

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

Iterable<Social> findByUserId(Long userId);

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

【讨论】:

    猜你喜欢
    • 2017-06-24
    • 2023-03-17
    • 2016-04-19
    • 2020-08-16
    • 1970-01-01
    • 1970-01-01
    • 2016-07-10
    • 2016-02-10
    • 1970-01-01
    相关资源
    最近更新 更多