@Document(collection = "users")
public class User {
@Id
private String id;
@DBRef(lazy = true)
private Set<User> following = new HashSet<>();
}
たとえば、私はそのようなことを考えます
User one = new User();
User two = new User();
one.follow(two);
userRepository.save(one);
現時点では、すべて正常に機能しています。しかしその後
two.follow(one);
userRepository.save(two);
プログラムをハングさせた 2 人のユーザーのうちの 1 人を取得しようとすると、ユーザー 1 にはユーザー 2 を含むリストがロードされましたが、ユーザー 2 にはこのユーザーのリストを含むユーザー 1 のリストが含まれ、最後にループが発生しました。リンク 2 オブジェクト用に追加のドキュメントを作成する最善の方法はありますか?