bo生成数据库表结构:
步骤:(在我们现在的框架的基础上)
配置libapay_domain/src/main/java/com/libapa/domain/conf/dao-context.xml 中增加红色的内容
<property name=“hibernateProperties”>
<props>
<prop key=“hibernate.dialect”>
org.hibernate.dialect.MySQLDialect
</prop>
<prop key=“hibernate.show_sql”>true</prop>
<prop key=“hibernate.cache.provider_class”>
org.hibernate.cache.EhCacheProvider
</prop>
<prop key=“hibernate.cache.use_query_cache”>true</prop>
<prop key=“hibernate.dialect”>org.hibernate.dialect.DerbyDialect
</prop>
<prop key=“hibernate.hbm2ddl.auto”>update</prop>
</props>
</property>
<property name=“configurationClass” value=“org.hibernate.cfg.AnnotationConfiguration” />
<property name=“namingStrategy” ref=“namingStrategy” />
<!--[if !supportLists]-->2. <!--[endif]-->写bo
//@entity 我们称这个类叫做实体,可以持久化的类
@Entity
//对应数据库的表(name 表名,catalog database的名称)
@Table(name = “lp_order_info”, catalog = “libapay”)
public class LpOrderInfo implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = -6052460988839555330L;
//将要把下面属性映射称数据库表中的对应的列
private String hid;
private UserLogonInfo userLogonInfo;
private BigDecimal subscriptionAmount;
private Date lkOrderDate;
private Date lkOrderTime;
private Date lpOrderDate;
private Set<LkOrderInfo> lkOrderInfos = new HashSet<LkOrderInfo>();
public LpOrderInfo() {
}
//声明实体的主键 =è对应数据库的主键
@Id
//下面两行是hibernate自动生成UUId的32位定长的ID
@GeneratedValue(generator=”system-uuid”)
@GenericGenerator(name=”system-uuid”, strategy = “uuid”)
//@Column对应数据库的列(name 列名,unique 是否唯一,nullable 是否为空,length 长度)
@Column(name = “hid”, unique = true, nullable = false, length = 32)
public String getHid() {
return this.hid;
}
public void setHid(String hid) {
this.hid = hid;
}
//@ManyToOne 说明实体LpOrderInfo 与 实体UserLogonInfo 之间存在多对一的关系,fetch = FetchType.LAZY,查询LpOrderInfo实体的时候,不需要加载与之关联的UserLogonInfo的实体,当你LpOrderInfo。getUserLogonInfo()的时候,才加载该实体)
//@JoinColumn 我个人理解:在解决多对一,一对多的不管是单向的还是双向的,都会在多的关系表中增加一列,@JoinColumn就可以达到这种目的,真正插入数据库的是被关联的“1”的方的实体的HID,其中的name是插入到数据库中的列名)
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = “user_logon_info_id”)
public UserLogonInfo getUserLogonInfo() {
return this.userLogonInfo;
}
public void setUserLogonInfo(UserLogonInfo userLogonInfo) {
this.userLogonInfo = userLogonInfo;
}
// precision = -2 可以实现数据库中的数据要是两位小数)
@Column(name = “subscription_amount”, precision = -2)
public BigDecimal getSubscriptionAmount() {
return this.subscriptionAmount;
}
public void setSubscriptionAmount(BigDecimal subscriptionAmount) {
this.subscriptionAmount = subscriptionAmount;
}
//@Temporal 这个注释是来帮助我们做时间,日期的映射,记住!
// TemporalType有三种类型:
TIME,如:“12:01:33“
DATE,如 :“2008-9-8”
TIMESTAMP “2008-9-8 12:01:33“
@Temporal(TemporalType.DATE)
@Column(name = “lk_order_date”, length = 0)
public Date getLkOrderDate() {
return this.lkOrderDate;
}
public void setLkOrderDate(Date lkOrderDate) {
this.lkOrderDate = lkOrderDate;
}
public void setSubOrderCount(String subOrderCount) {
this.subOrderCount = subOrderCount;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = “create_dt”, length = 0)
public Date getCreateDt() {
return this.createDt;
}
public void setCreateDt(Date createDt) {
this.createDt = createDt;
}
//@OneToMany 表示该实体(LpOrderInfo)与LkOrderInfo实体之间的关系是一对多的关系,可以这样通俗的理解:一个LpOrderInfo的实体中可以有多个LkOrderInfo实体,一个LkOrderInfo实体只能属于某一个特定的LpOrderInfo的实体。
// cascade 表示表之间的级联关系,PERSIST, MERGE
// fetch
@OneToMany(cascade = CascadeType.PERSIST,CascadeType.MERGE}, fetch = FetchType.LAZY, mappedBy = “lpOrderInfo”)
public Set<LkOrderInfo> getLkOrderInfos() {
return lkOrderInfos;
}
public void setLkOrderInfos(Set<LkOrderInfo> lkOrderInfos) {
this.lkOrderInfos = lkOrderInfos;
}
}
@Entity
@Table(name = “lk_order_info”, catalog = “libapay”)
public class LkOrderInfo implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = 570872858109663977L;
private String hid;
private LpOrderInfo lpOrderInfo;
@Id
@GeneratedValue(generator=“system-uuid”)
@GenericGenerator(name=“system-uuid”, strategy = “uuid”)
@Column(name = “hid”, unique = true, nullable = false, length = 32)
public String getHid() {
return this.hid;
}
public void setHid(String hid) {
this.hid = hid;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = “lp_order_info_id”)
public LpOrderInfo getLpOrderInfo() {
return lpOrderInfo;
}
public void setLpOrderInfo(LpOrderInfo lpOrderInfo) {
this.lpOrderInfo = lpOrderInfo;
}
}