У меня есть энтити: Train и Seat. Они связаны реляцией one-to-many.
Train
@Entity
@Table(name = "train")
public class Train {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Column(name = "name")
private String name;
@OneToMany(mappedBy = "train", cascade = CascadeType.ALL)
private Set<Seat> seats;
...
// Геттеры и сеттеры
Seat
@Entity
@Table(name = "seat")
public class Seat {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Column(name = "carriage")
private Integer carriage;
@Column(name = "seat")
private Integer seat;
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "train_id", nullable = false)
private Train train;
...
// Другой код
При попытке получить поезд у меня возникает ошибка:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.slandshow.models.Train.seats, could not initialize proxy - no Session
В чём проблема?