私はSDN 4(v4.2.1)、Springブート(1.5.2)、Neo4j(v3.1.0)を使用していますが、save()メソッドで単純な関係を削除することはできません。Spring Data Neo4jとの関係を削除
@NodeEntity
public class A extends MyModel {
@Relationship(type="link")
private B b;
//Getters and setters
}
@NodeEntity
public class B extends MyModel {
@Relationship(type="link", direction=Relationship.INCOMING)
private List as;
//Getters and setters
}
public interface ARepository implements GraphRepository {
}
public interface BRepository implements GraphRepository {
}
//Create relationship
A a a = ...;
B b = ...;
a.setB(b);
a = aRepository.save(a); // works
//Delete relationship
a.setB(null);
aRepository.save(a); // Not works
AとBの関係を削除するにはどうすればよいですか?
編集
ありがとうございました。
フォームの検証後に行う方法。
@PostMapping(FORM)
public String form(@Valid @ModelAttribute("object") A a, BindingResult result, Model model, RedirectAttributes att, HttpServletRequest request) {
log.info("/form");
if (result.hasErrors()) {
return form(model, a, request);
}
try {
// a.getB() is null and a.getId() isn't null
a = aService.save(a); // a.getB() isn't delete
if (a.getId() == null)
att.addFlashAttribute(MSG, a.getName() + " : create !");
else
att.addFlashAttribute(MSG, a.getName() + " : modify !");
} catch (Exception e) {
model.addAttribute(MSG, e.getMessage());
log.error(e.getMessage(), e);
return form(model, a, request);
}
return redirect(LISTE);
}
ここでは、私のオブジェクトはセッションに含まれていませんが、idはspring mvcで埋められました。 bがドロップダウンリストで選択されました。
@Transactionalで呼び出しの基本シーケンスをラップしましたか? – digx1
はい、私は自分のメソッドで@Transactionalを使用します。 –
これは間違いなく機能するはずです。ここでチケットをお持ちください:https://jira.spring.io/browse/DATAGRAPH zipやgithubのいずれかのコードサンプルがあれば、それを複製することができます。 – digx1