我有社交模式:
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。
答案 0 :(得分:0)
您是否尝试在存储库中实现自己的find方法,如:
Iterable<Social> findByUserId(Long userId);
是否正确创建了索引(请参阅Null return using GraphRepository from Spring Data for Neo4j)?