@Entity
@Table(name = "customer_order_hd")
@NamedQuery(name = "CustomerOrderHd.findAll", query = "SELECT c FROM CustomerOrderHd c")
public class CustomerOrderHd implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "order_no", unique = true, nullable = false)
private Long orderNo;
@Column(name = "create_by", length = 50)
private String createBy;
@Column(name = "create_date")
private Timestamp createDate;
@Column(name = "customer_id")
private Long customerId;
@Temporal(TemporalType.DATE)
@Column(name = "order_date")
private Date orderDate;
@Column(name = "order_remark", length = 250)
private String orderRemark;
@Column(name = "order_status", length = 10)
private String orderStatus;
@Column(name = "order_total_amount", precision = 10, scale = 2)
private BigDecimal orderTotalAmount;
@Column(name = "purchased_location", length = 50)
private String purchasedLocation;
@Column(name = "purchaser_name", length = 80)
private String purchaserName;
@Column(name = "staff_user_id", length = 50)
private String staffUserId;
@Column(name = "update_by", length = 50)
private String updateBy;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "update_date")
private Date updateDate;
// bi-directional many-to-one association to CustomerOrderDet
@OneToMany(mappedBy = "customerOrderHd")
//@OneToMany(cascade={CascadeType.MERGE, CascadeType.ALL})
//@JoinColumn(name="order_no", nullable=false)
private List<CustomerOrderDet> customerOrderDets;
// bi-directional many-to-one association to CustomerOrderTran
@OneToMany(mappedBy = "customerOrderHd", cascade = CascadeType.MERGE)
private List<CustomerOrderTrans> customerOrderTranses;
@Entity
@Table(name="customer_order_det")
@NamedQuery(name="CustomerOrderDet.findAll", query="SELECT c FROM CustomerOrderDet c")
public class CustomerOrderDet implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="order_det_id", unique=true, nullable=false)
private Long orderDetId;
@Column(name="create_by", length=50)
private String createBy;
@Column(name="create_date")
private Timestamp createDate;
@Column(name="item_remark", length=100)
private String itemRemark;
@Column(name="item_total_amout", precision=10, scale=2)
private BigDecimal itemTotalAmout;
@Column(name="order_qty")
private int orderQty;
@Column(name="update_by", length=50)
private String updateBy;
@Temporal(TemporalType.TIMESTAMP)
@Column(name="update_date")
private Date updateDate;
//bi-directional many-to-one association to CustomerOrderHd
@ManyToOne(cascade={CascadeType.MERGE, CascadeType.ALL})
@JoinColumn(name="order_no", nullable=false)
private CustomerOrderHd customerOrderHd;
@OneToMany(mappedBy = "customerOrderHd"):意思是让对方维护关联关系,如果保存CustomerOrderHd对象不会级联更新customerOrderDets;
@JoinColumn(name="order_no", nullable=false):name的值为外键字段名
mappedBy和JoinColumn的意思正好相反,不能同时用在一个字段上。
注意:many方即子表方不管怎样都有权维护关联关系。