-------如:订单和订单项映射关系------------------------一个订单可以有多个订单项,一个订单项只能属于一个订单-------
/**
* Entity - 订单
*
* @author SHOP++ Team
* @version 3.0
*/
@Entity
@Table(name = "xx_order")
@SequenceGenerator(name = "sequenceGenerator", sequenceName = "xx_order_sequence")
public class Order extends BaseEntity {
/** 订单项 */
private List<OrderItem> orderItems = new ArrayList<OrderItem>();
/**
* 获取订单项
*
* @return 订单项
*/
@Valid
@NotEmpty
@OneToMany(mappedBy = "order", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
@OrderBy("isGift asc")
public List<OrderItem> getOrderItems() {
return orderItems;
}
/**
* 设置订单项
*
* @param orderItems
* 订单项
*/
public void setOrderItems(List<OrderItem> orderItems) {
this.orderItems = orderItems;
}
}
--------------------------------
public class OrderItem extends BaseEntity {
/** 订单 */
private Order order;
/**
* 获取订单
*
* @return 订单
*/
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "orders", nullable = false, updatable = false)
@JSONField(serialize=false)
public Order getOrder() {
return order;
}
/**
* 设置订单
*
* @param order
* 订单
*/
public void setOrder(Order order) {
this.order = order;
}
}
====================================================================================================================================
如:会员和购物车的映射关系,一个会员只能有一个购物车,一个购物车只能属于一个会员
public class Member extends BaseEntity {
/**
* 获取购物车
*
* @return 购物车
*/
@OneToOne(mappedBy = "member", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
@JSONField(serialize = false)
public Cart getCart() {
return cart;
}
/**
* 设置购物车
*
* @param cart
* 购物车
*/
public void setCart(Cart cart) {
this.cart = cart;
}
}
----------------------------------------------
public class Cart extends BaseEntity {
/**
* 获取会员
*
* @return 会员
*/
@OneToOne(fetch = FetchType.LAZY)
@JSONField(serialize=false)
public Member getMember() {
return member;
}
/**
* 设置会员
*
* @param member
* 会员
*/
public void setMember(Member member) {
this.member = member;
}
}
==============================================================================================================================
=============list 和set .一般都用set泛型集合=====
/** 会员 */
private Set<Member> members = new HashSet<Member>();
/** 订单项 */
private List<OrderItem> orderItems = new ArrayList<OrderItem>();