我有这样的实体:
@Entity
@Table(name = "ROOM")
public class Room implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "room_id")
private Integer id;
@Column(name = "number")
private String number; //immutable
@Column(name = "capacity")
private Integer capacity;
}
如何在另一个实体中映射Room的两个实例。就像这样:
@Entity
@Table(name = "BUILDING")
public class Building implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "building_id")
private Integer id;
@Column(name = "LeftRoom")
private Room left;
@Column(name = "RightRoom")
private Room right;
}