I cannot run my Spring Boot application because I get an error:
Unable to build Hibernate SessionFactory; nested exception is org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags: [ru.axothy.backdammon.gameservice.model.Board.towers, ru.axothy.backdammon.gameservice.model.Tower.chips]
My entities:
Board.class:
@Getter @Setter
@Entity
@Table(name = "boards")
public class Board implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "BOARD_ID")
private int boardId;
@OneToMany(fetch = FetchType.EAGER)
@JsonManagedReference
private List<Tower> towers = new ArrayList<>();
}
Tower.class:
@Entity
@Getter @Setter
@Table(name = "towers")
public class Tower implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "TOWER_ID", nullable = false)
private int towerId;
@OneToMany(fetch = FetchType.EAGER)
@JsonManagedReference
private List<Chip> chips = new ArrayList<>();
}
And chip.class:
@Getter @Setter
@Entity
@Table(name = "chips")
public class Chip implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "CHIP_ID")
private int chipId;
}
I know that one of the solutions is to change List to Set, but I need List.