【发布时间】:2016-04-19 12:42:49
【问题描述】:
我正在使用 SDN 4 和 neo4j-ogm 1.1.4
我正在尝试使用 findById(Long id) GraphRepository 获取我的数据,但始终返回 null。之后,我尝试使用 findByName(String name) 并且它起作用了。我知道有使用 findOne(Long id, int depth) 的替代方法,但是当我想进行自定义查询时,例如 findByObjectId(Long id),就会很麻烦。
在 neo4j 尝试手动查询后,它也返回 null。那么这有什么问题吗?
@NodeEntity
public class Fetch1 {
@GraphId Long id;
private String name;
@Relationship(type="HAS_FETCH2")
@JsonIgnore
private List<Fetch2> fetch2;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Relationship(type="HAS_FETCH2")
@JsonIgnore
public List<Fetch2> getFetch2() {
return fetch2;
}
@Relationship(type="HAS_FETCH2")
@JsonIgnore
public void setFetch2(List<Fetch2> fetch2) {
this.fetch2 = fetch2;
}
@Override
public String toString() {
return "Fetch1 [id=" + id + ", name=" + name + ", fetch2=" + fetch2 + "]";
}
}
@NodeEntity
public class Fetch2 {
@GraphId Long id;
private String name;
@Relationship(type="HAS_FETCH2", direction=Relationship.INCOMING)
@JsonIgnore
private Fetch1 fetch1;
@Relationship(type="HAS_FETCH3")
@JsonIgnore
private List<Fetch3> fetch3;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Relationship(type="HAS_FETCH2", direction=Relationship.INCOMING)
@JsonIgnore
public Fetch1 getFetch1() {
return fetch1;
}
@Relationship(type="HAS_FETCH2", direction=Relationship.INCOMING)
@JsonIgnore
public void setFetch1(Fetch1 fetch1) {
this.fetch1 = fetch1;
}
@Relationship(type="HAS_FETCH3")
@JsonIgnore
public List<Fetch3> getFetch3() {
return fetch3;
}
@Relationship(type="HAS_FETCH3")
@JsonIgnore
public void setFetch3(List<Fetch3> fetch3) {
this.fetch3 = fetch3;
}
@Override
public String toString() {
return "Fetch2 [id=" + id + ", name=" + name + ", fetch1=" + fetch1 + ", fetch3=" + fetch3 + "]";
}
}
这是我的仓库
public interface Fetch1Repository extends GraphRepository<Fetch1>{
Fetch1 findById(Long id);
Fetch1 findByFetch2Id(Long id);
Fetch1 findByFetch2Name(String name);
}
【问题讨论】:
标签: spring fetch spring-data-neo4j-4