【发布时间】:2016-10-31 00:58:41
【问题描述】:
我的一对多关系有问题。 我的问题是当我将租户添加到公寓时,它不会将租户中的列值设置为 ApartmentID。问题是我与其他班级的关系完全相同,而且他们工作得很好......有谁知道为什么它不工作? 谢谢
公寓:
@Entity
public class Apartment {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="ApartmentID",unique = true, nullable = false)
public int apartmentID;
@OneToMany(mappedBy = "apartment", cascade = CascadeType.ALL)
private List<Tenant> tenants;
}
租户:
@Entity
public class Tenant {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="TenantID",unique = true, nullable = false)
public int tenantID;
@ManyToOne
@JoinColumn(name = "ApartmentID")
private Apartment apartment;
}
【问题讨论】:
标签: java hibernate jpa one-to-many bidirectional