JPA 或者Hibernate 实体类说明
这里简单介绍Hibernate的Annotation注解
一、声明实体
@Entity
对实体注释。任何Hibernate映射对象都要有这个注释
@Table
声明此对象映射到数据库的数据表,通过它可以为实体指定表(talbe),目录(Catalog)和schema的名字。该注释不是必须的,如果没有则系统使用默认值(实体的短类名)。
@Version
该注释可用于在实体Bean中添加乐观锁支持。
二、声明主键
@Id
声明此属性为主键。该属性值可以通过应该自身创建,但是Hibernate推荐通过Hibernate生成
@GeneratedValue
指定主键的生成策略。有如下四个值
TABLE:使用表保存id值
IDENTITY:identitycolumn
SEQUENCR :sequence
AUTO:根据数据库的不同使用上面三个
三、声明普通属性
@Column
可以放在属性或者get方法上面
@Column(name=" contact_name ")
private String contactName;
或者
@Column(name=" contact_name ")
public String getName() {
return name;
}
注:当POJO有属性不需要映射的时候一定要用@Transitent修饰,该注释表示此属性与表没有映射关系,只是一个暂时的属性。
如下 dingDiffId 跟数据库没关系,不需要存,那么就在属性上面加@Transitent
@Entity @Table(name="order_info") public class OrderInfoDO extends BaseUpdateDO { /** 订单编号 */ @Id private String id = null; /** 父单号 *//* @Column(name="parent_order_num") private String parentOrderNum = null;*/ /** 产品等级 */ @Column(name="product_grade") private Integer productGrade = null; /** 产品名称 */ @Column(name="product_name") private String productName = null; /** 优惠卷编号 */ @Column(name="coupon_id") private String couponId = null; /** 收获地址信息 *//* @OneToOne(cascade={CascadeType.REFRESH}) @JoinColumn(name="order_address_id") private OrderAddressDO address = null;*/ /** 钉钉编号 */ @Column(name="ding_id") private String dingId = null; /** 钉钉应用编号 *//* @Column(name="app_id") private String appId = null;*/ /** 用户编号 */ @Column(name="user_id") private String userId = null; /** 用户名称 */ @Column(name="user_name") private String userName = null; /** 公司 */ private String company = null; /** 邮箱 */ private String email = null; /** 服务用户编号 *//* @Column(name="service_user_id") private String serviceUserId = null; *//** 服务用户名称 *//* @Column(name="service_user_name") private String serviceUserName = null; *//** 订单类别 *//* @Column(name="oder_type") private String oderType = null;*/ /** 产品类型组 */ @Column(name="product_group", nullable=false) private String productGroup = null; /** 产品类型 */ @Column(name="product_type") private int productType = 0; /** 产品类型值 */ @Column(name="product_type_value") private String productTypeValue = null; /** 支付方式 *//* @Column(name="pay_type") private Integer payType = null;*/ /** 支付账户名称 */ @Column(name="pay_name") private String payName = null; /** 设计价格 单位:分 */ @Column(name="designer_money") private int designerMoney = 0; /** 制作价格 单位:分 *//* @Column(name="make_money") private Integer makeMoney = null;*/ /** 用户下订单时补的差价金额 单位:分 */ @Column(name="difference_price") private int differencePrice = 0; /** 支付金额 单位:分 */ @Column(name="pay_money") private int payMoney = 0; /** 设计退款金额 单位:分 */ @Column(name="refund_designer_money") private Integer refundDesignerMoney = null; /** 制作退款金额 单位:分 *//* @Column(name="refund_make_money") private Integer refundMakeMoney = null;*/ /** 总共退款金额 单位:分 */ @Column(name="refund_total_money") private Integer refundTotalMoney = null; /** 退款账户 */ @Column(name="refund_account") private String refundAccount = null; /** 退款备注信息 */ @Column(name="refund_remark") private String refundRemark = null; /** 单价 单位:分 */ @Column(name="unit_price") private int unitPrice = 0; /** 产品数量 */ @Column(name="product_num") private int productNum = 0; /** 是否制作 *//* @Column(name="is_make") private boolean isMake = false; *//** 制作尺寸 *//* @Column(name="make_size") private String makeSize = null; *//** 制作数量 *//* @Column(name="make_num") private String makeNum = null;*/ /** 源文件 */ @Column(name="source_file") private String sourceFile = null; /** 备注 */ @Column(name="remarks") private String remarks = null; /** 评价信息 */ @Column(name="evaluate_msg") private String evaluateMsg = null; /** 评价服务态度 */ @Column(name="evaluate_service") private int evaluateService = 0; /** 评价设计水平 */ @Column(name="evaluate_design") private int evaluateDesign = 0; /** 服务流程编号 */ @Column(name="flow_id") private String flowId = null; /** 订单状态 */ private int status = 0; /** 处理状态 */ @Column(name="handle_status") private int handleStatus = 0; /** 退款状态 */ @Column(name="refund_status") private Integer refundStatus = null; /** 支付时间 */ @Column(name="pay_time") private Timestamp payTime = null; /** 联系方式 */ private String tel = null; /** 延期说明 */ @Column(name="delay_remark") private String delayRemark = null; /** 用户定稿稿件编号 */ @Column(name="final_id") private String finalId = null; /** 初稿用户不满意标识符 true:不满意 */ @Column(name="first_unsatisfy") private Boolean firstUnsatisfy = null; /** 初稿稿件集合 */ @Transient private List<OrderRecordDO> firsts = null; /** CRM推送状态 false:未推送 */ /*@Column(name="crm_flag") private boolean crmFlag = false;*/ /** 钉钉订单编号*/ @Column(name="ding_order_id") private String dingOrderId = null; /** 创建日期到天格式*/ @Column(name="est_date") private Integer estDate = null; /** order_difference 表用的ding_diff_id*/ @Transient private String dingDiffId = null; public String getId() { return id; } public void setId(String id) { this.id = id; } /*public String getParentOrderNum() { return parentOrderNum; } public void setParentOrderNum(String parentOrderNum) { this.parentOrderNum = parentOrderNum; }*/ public Integer getProductGrade() { return productGrade; } public void setProductGrade(Integer productGrade) { this.productGrade = productGrade; } public String getProductName() { return productName; } public void setProductName(String productName) { this.productName = productName; } public String getCouponId() { return couponId; } public void setCouponId(String couponId) { this.couponId = couponId; } /*public OrderAddressDO getAddress() { return address; } public void setAddress(OrderAddressDO address) { this.address = address; }*/ public String getDingId() { return dingId; } public void setDingId(String dingId) { this.dingId = dingId; } /*public String getAppId() { return appId; } public void setAppId(String appId) { this.appId = appId; }*/ public String getUserId() { return userId; } public void setUserId(String userId) { this.userId = userId; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getCompany() { return company; } public void setCompany(String company) { this.company = company; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } /*public String getServiceUserId() { return serviceUserId; } public void setServiceUserId(String serviceUserId) { this.serviceUserId = serviceUserId; } public String getServiceUserName() { return serviceUserName; } public void setServiceUserName(String serviceUserName) { this.serviceUserName = serviceUserName; } public String getOderType() { return oderType; } public void setOderType(String oderType) { this.oderType = oderType; }*/ public String getProductGroup() { return productGroup; } public void setProductGroup(String productGroup) { this.productGroup = productGroup; } public int getProductType() { return productType; } public void setProductType(int productType) { this.productType = productType; } public String getProductTypeValue() { return productTypeValue; } public void setProductTypeValue(String productTypeValue) { this.productTypeValue = productTypeValue; } /*public Integer getPayType() { return payType; } public void setPayType(Integer payType) { this.payType = payType; }*/ public String getPayName() { return payName; } public void setPayName(String payName) { this.payName = payName; } public int getDesignerMoney() { return designerMoney; } public void setDesignerMoney(int designerMoney) { this.designerMoney = designerMoney; } /*public Integer getMakeMoney() { return makeMoney; } public void setMakeMoney(Integer makeMoney) { this.makeMoney = makeMoney; }*/ public int getDifferencePrice() { return differencePrice; } public void setDifferencePrice(int differencePrice) { this.differencePrice = differencePrice; } public int getPayMoney() { return payMoney; } public void setPayMoney(int payMoney) { this.payMoney = payMoney; } public Integer getRefundDesignerMoney() { return refundDesignerMoney; } public void setRefundDesignerMoney(Integer refundDesignerMoney) { this.refundDesignerMoney = refundDesignerMoney; } /*public Integer getRefundMakeMoney() { return refundMakeMoney; } public void setRefundMakeMoney(Integer refundMakeMoney) { this.refundMakeMoney = refundMakeMoney; }*/ public Integer getRefundTotalMoney() { return refundTotalMoney; } public void setRefundTotalMoney(Integer refundTotalMoney) { this.refundTotalMoney = refundTotalMoney; } public String getRefundAccount() { return refundAccount; } public void setRefundAccount(String refundAccount) { this.refundAccount = refundAccount; } public String getRefundRemark() { return refundRemark; } public void setRefundRemark(String refundRemark) { this.refundRemark = refundRemark; } public int getUnitPrice() { return unitPrice; } public void setUnitPrice(int unitPrice) { this.unitPrice = unitPrice; } public int getProductNum() { return productNum; } public void setProductNum(int productNum) { this.productNum = productNum; } /*public boolean isMake() { return isMake; } public void setMake(boolean make) { isMake = make; } public String getMakeSize() { return makeSize; } public void setMakeSize(String makeSize) { this.makeSize = makeSize; } public String getMakeNum() { return makeNum; } public void setMakeNum(String makeNum) { this.makeNum = makeNum; }*/ public String getSourceFile() { return sourceFile; } public void setSourceFile(String sourceFile) { this.sourceFile = sourceFile; } public String getRemarks() { return remarks; } public void setRemarks(String remarks) { this.remarks = remarks; } public String getEvaluateMsg() { return evaluateMsg; } public void setEvaluateMsg(String evaluateMsg) { this.evaluateMsg = evaluateMsg; } public int getEvaluateService() { return evaluateService; } public void setEvaluateService(int evaluateService) { this.evaluateService = evaluateService; } public int getEvaluateDesign() { return evaluateDesign; } public void setEvaluateDesign(int evaluateDesign) { this.evaluateDesign = evaluateDesign; } public String getFlowId() { return flowId; } public void setFlowId(String flowId) { this.flowId = flowId; } public int getStatus() { return status; } public void setStatus(int status) { this.status = status; } public int getHandleStatus() { return handleStatus; } public void setHandleStatus(int handleStatus) { this.handleStatus = handleStatus; } public Integer getRefundStatus() { return refundStatus; } public void setRefundStatus(Integer refundStatus) { this.refundStatus = refundStatus; } public Timestamp getPayTime() { return payTime; } public void setPayTime(Timestamp payTime) { this.payTime = payTime; } public String getTel() { return tel; } public void setTel(String tel) { this.tel = tel; } public String getDelayRemark() { return delayRemark; } public void setDelayRemark(String delayRemark) { this.delayRemark = delayRemark; } public String getFinalId() { return finalId; } public void setFinalId(String finalId) { this.finalId = finalId; } public Boolean isFirstUnsatisfy() { return firstUnsatisfy; } public void setFirstUnsatisfy(Boolean firstUnsatisfy) { this.firstUnsatisfy = firstUnsatisfy; } public List<OrderRecordDO> getFirsts() { return firsts; } public void setFirsts(List<OrderRecordDO> firsts) { this.firsts = firsts; } /*public boolean isCrmFlag() { return crmFlag; } public void setCrmFlag(boolean crmFlag) { this.crmFlag = crmFlag; }*/ public String getDingOrderId() { return dingOrderId; } public void setDingOrderId(String dingOrderId) { this.dingOrderId = dingOrderId; } public Integer getEstDate() { return estDate; } public void setEstDate(Integer estDate) { this.estDate = estDate; } public String getDingDiffId() { return dingDiffId; } public void setDingDiffId(String dingDiffId) { this.dingDiffId = dingDiffId; } @Override public String toString() { return "OrderInfoDO{" + "id='" + id + '\'' + ", productGrade=" + productGrade + ", productName='" + productName + '\'' + ", couponId='" + couponId + '\'' + ", dingId='" + dingId + '\'' + ", userId='" + userId + '\'' + ", userName='" + userName + '\'' + ", company='" + company + '\'' + ", email='" + email + '\'' + ", productGroup='" + productGroup + '\'' + ", productType=" + productType + ", productTypeValue='" + productTypeValue + '\'' + ", payName='" + payName + '\'' + ", designerMoney=" + designerMoney + ", differencePrice=" + differencePrice + ", payMoney=" + payMoney + ", refundDesignerMoney=" + refundDesignerMoney + ", refundTotalMoney=" + refundTotalMoney + ", refundAccount='" + refundAccount + '\'' + ", refundRemark='" + refundRemark + '\'' + ", unitPrice=" + unitPrice + ", productNum=" + productNum + ", sourceFile='" + sourceFile + '\'' + ", remarks='" + remarks + '\'' + ", evaluateMsg='" + evaluateMsg + '\'' + ", evaluateService=" + evaluateService + ", evaluateDesign=" + evaluateDesign + ", flowId='" + flowId + '\'' + ", status=" + status + ", handleStatus=" + handleStatus + ", refundStatus=" + refundStatus + ", payTime=" + payTime + ", tel='" + tel + '\'' + ", delayRemark='" + delayRemark + '\'' + ", finalId='" + finalId + '\'' + ", firstUnsatisfy=" + firstUnsatisfy + ", firsts=" + firsts + ", dingOrderId=" + dingOrderId + ", estDate=" + estDate + ", dingDiffId=" + dingDiffId + "} " + super.toString(); } }