【发布时间】:2013-05-10 10:44:24
【问题描述】:
我有 2 张表 customer 和 customerhistory。 customhistory 有外键 customerId,它引用了客户的 customerId。在 JPA 生成的实体中,我在 customerhistory 类中有一个客户对象,而我只想将 customerId 保存在 consumerhistory 表中
我得到了正确的 customerId,但是当我想保存属性 customerId 时,我只有 customer 对象,但在 consumerhistory 的自动生成实体类中没有 customerId
@Entity
public class Customerhistory implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int primarykeyId;
//bi-directional many-to-one association to Customer
@ManyToOne
@JoinColumn(name="CustomerId")
private Customer customer;
如上所示,我在实体 customerHistory 中没有 customerId。如何保存?
【问题讨论】:
标签: java database hibernate jpa