【发布时间】:2018-06-05 15:44:28
【问题描述】:
我正在为本季度的决赛使用 JPA 和 Hibernate。我有一个无限循环。我尝试使用@ManyToMany,但老师不希望我们使用它。所以我用了这个。
这是第一个实体,
@Entity
@Table(name = "Routes")
public class Routes {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
@Column(name = "id_route")
private Long id;
@OneToOne
private Airport origin;
@OneToOne
private Airport destination;
@Column(name = "distance")
private float distance;
@OneToMany(fetch = FetchType.EAGER, mappedBy = "route")
private List<RouteXCabin> cabinas= new ArrayList<>();
第二个,
@Entity
@Table(name = "Cabins")
public class Cabin {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
@Column(name = "id_cabin")
private int id;
@NotBlank
@Column(name = "name")
private String nombre;
最后是连接实体/表
@Table(name = "routes_x_cabins")
public class RouteXCabin {
@Id
@GeneratedValue
@Column(name = "id_Rxc")
private Long id;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "fk_id_route")
private Routes route;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "fk_id_cabin")
private Cabin cabin;
我有这个循环Image。 知道如何解决这个问题吗? 谢谢
【问题讨论】:
-
“我有这个循环”是什么意思?关联是双向的,您还期望得到什么?我看不到任何需要解决的问题
-
我无法将答案转换为问题所在的 json。我使用 DTO 解决了这个问题。 @crizzis
标签: hibernate jpa annotations