【发布时间】: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