Dzień dobry,
W swoim programie posiadam dwa modele User i Room. Ponadto posiadam ich ormowe odpowiedniki (UserEntity + RoomEntity).
W UserEntity mam:
public User toUser()
public static UserEntity fromUser(User user)
Analogicznie w RoomEntity
Te obiekty mają zależność 1:N dwukierunkową (user ma pole room i room ma pole Set<User>)
W RoomEntity implementacja wygląda tak:
public Room toRoom() {
return new Room(name, maxUsers, users.stream().map(UserEntity::toUser).collect(Collectors.toSet()));
}
W UserEntity tak:
public User toUser() {
return new User(nickname, ip, heartbeat, Option.of(room).map(RoomEntity::toRoom));
}
Jak mapuje RoomEntity do Room to mam zależność kołową i robi się StackOverflow, jak takie coś rozwiązać?