最初のpersist()を削除すると以下のテストは失敗します。 Setをインスタンス化するためにNodeEntityを保持する必要があるのはなぜですか?これを行うにはよりよい方法がありますか?私はネセサリーよりも頻繁にデータベースに書き込む必要はありません。私が言及した行を削除する場合Springデータグラフ内のNeo4J NodeEntity間の関係をpersistを2回呼び出さずに保持する方法
@Test
public void testCompetenceCreation() {
Competence competence = new Competence();
competence.setName("Testcompetence");
competence.persist(); //test fails if this line is removed
Competence competenceFromDb = competenceRepository.findOne(competence.getId());
assertEquals(competence.getName(), competenceFromDb.getName());
Education education = new Education();
education.setName("Bachelors Degree");
competence.addEducation(education);
competence.persist();
assertEquals(competence.getEducations(), competenceFromDb.getEducations());
}
、例外怒鳴るが発生します。
@JsonIgnoreProperties({"nodeId", "persistentState", "entityState"})
@NodeEntity
public class Education {
@GraphId
private Long id;
@JsonBackReference
@RelatedTo(type = "COMPETENCE", elementClass = Competence.class, direction = Direction.INCOMING)
private Competence competence;
@Indexed
private String name;
public Long getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Education.class
@JsonIgnoreProperties({"nodeId", "persistentState", "entityState"})
@NodeEntity
public class Competence {
@RelatedTo(type = "EDUCATION", elementClass = Education.class)
private Set<Education> educations;
public Set<Education> getEducations() {
return educations;
}
public void addEducation(Education education) {
this.educations.add(education);
}
}
:
を
java.lang.NullPointerException
at com.x.entity.Competence.addEducation(Competence.java:54)
Competence.classをスローします
感謝を返すことによって、その後findOneない場合は
-Competenceも[で提供]。どのようにして永続性を使用する必要があるのかを今理解しており、アノテーションのリレーションシップタイプについてのメモも正しいと思います。あなたは私がJira問題に書いてもらいたいことを説明することができますか?私が理解しているように、これはバグではなく、Spring Data Graphの仕組みを完全に理解しているわけではありません:-) –
問題を作成し、このディスカッションにリンクしてください。説明として、コレクションフィールドを一貫性のある方法で初期化します。ありがとう –
完了!再度、あなたの助けをありがとう、非常に感謝します。 https://jira.springsource.org/browse/DATAGRAPH-135 –