為了持久化類之間的繼承關系映射到數據庫中,可以采用為每個具體的子類對應一個關系表,沒有父類數據表
數據表:
customer:
id int(4) <pk>
name varchar(20)
phone varchar(20)
oneoffOrders:一次性付款訂單表
id int(4) <pk>
customer_id int(4)
orderno varchar(20)
moeny decimal(10,2)
rebate decimal(10,2) 折扣金額
dividedOrders:分期付款訂單表
id int(4) <pk>
customer_id int(4)
moeny decimal(10,2)
rebate decimal(10,2)
months int(4)
持久化類:
public class Customer implements Serializable{
private Integer id;
private String name;
private String phone;
private Set orders=new HashSet();
pulic Customer(){
}
}
//父類
public abstrace class Orders{
private Integer id;
private String orderno;
private Double moeny;
private Customer customer;
public Orders(){
}
}
//子類 Oneofforders
public class Oneofforders extends Orders implements Serializable{
private Double rebate;
public Oneofforders(){
}
}
//子類 Dividedorders
public class Dividedorders extends Orders implements Serializable}
private Integer months;
public Dividedorders(){
}
}
hbm.xml
<hibernate-mapping package="com.lhb.vo">
<class name="Customer" table="customer">
<id name="id" column="id" type="integer">
<generator class="native"/>
</id>
<property name="name" column="name" type="string"/>
<property name="phone" column="phone" type="string"/>
<set name="orders" lazy="false" cascade="all" inverse="true">
<key column="customer_id"/>
<one-to-many class="com.lhb.vo.Orders"/>
</set>
</class>
</hibernate-mapping>
<hibernate-mapping package="com.lhb.vo">
<class name="Oneofforders" table="oneofforders">
<id name="id" column="id" type="integer">
<generator class="native"/>
</id>
<property name="orderno" column="orderno" type="string"/>
<property name="ordername" column="ordername" type="string"/>
<property name="rebate" column="rebate" type="double"/>
<many-to-one name="customer" column="customer_id" class="com.lhb.vo.Customer" lazy="false" not-null="true"/>
</class>
</hibernate-mapping>
<hibernate-mapping package="com.lhb.vo">
<class name="Dividedorders" table="dividedorders">
<id name="id" column="id" type="integer">
<generator class="native"/>
</id>
<property name="orderno" column="orderno" type="string"/>
<property name="money" column="money" type="double"/>
<proerty name="months" column="months" type="double"/>
<many-to-one name="customer" column="customer_id" class="com.lhb.vo.Customer" lazy="false" not-null="true"/>
</class>
</hibernate-mapping>
| |||||||||
日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
---|---|---|---|---|---|---|---|---|---|
27 | 28 | 29 | 30 | 1 | 2 | 3 | |||
4 | 5 | 6 | 7 | 8 | 9 | 10 | |||
11 | 12 | 13 | 14 | 15 | 16 | 17 | |||
18 | 19 | 20 | 21 | 22 | 23 | 24 | |||
25 | 26 | 27 | 28 | 29 | 30 | 31 | |||
1 | 2 | 3 | 4 | 5 | 6 | 7 |
長春語林科技歡迎您!
常用鏈接
留言簿(6)
隨筆分類
- ajax(2)
- android(5)
- css(2)
- db2(2)
- docker(10)
- flex(22)
- hibernate(16)
- html5(9)
- java(12)
- java8(8)
- jquery(4)
- js(30)
- jsp(2)
- jstl(3)
- linux(14)
- mongodb(1)
- mui(1)
- mysql(14)
- oracle(3)
- spring(8)
- sqlserver(4)
- struts(9)
- struts2(13)
- tomcat(6)
- UML(1)
- util(50)
- vue(1)
- weblogic(1)
隨筆檔案
- 2020年4月 (1)
- 2020年3月 (1)
- 2020年2月 (2)
- 2019年10月 (2)
- 2019年9月 (1)
- 2019年7月 (1)
- 2019年4月 (1)
- 2019年1月 (1)
- 2018年12月 (2)
- 2018年8月 (1)
- 2018年6月 (3)
- 2018年5月 (9)
- 2018年3月 (9)
- 2017年12月 (1)
- 2017年10月 (1)
- 2017年7月 (1)
- 2017年6月 (1)
- 2017年5月 (1)
- 2017年3月 (3)
- 2017年2月 (2)
- 2017年1月 (1)
- 2016年12月 (1)
- 2016年11月 (1)
- 2016年9月 (1)
- 2016年4月 (3)
- 2016年3月 (2)
- 2015年8月 (5)
- 2015年3月 (1)
- 2014年8月 (1)
- 2012年11月 (1)
- 2012年5月 (2)
- 2012年4月 (5)
- 2011年12月 (1)
- 2011年10月 (3)
- 2011年9月 (2)
- 2011年8月 (10)
- 2011年7月 (3)
- 2011年6月 (4)
- 2011年5月 (2)
- 2011年4月 (3)
- 2011年3月 (12)
- 2011年1月 (2)
- 2010年12月 (1)
- 2010年9月 (2)
- 2010年8月 (4)
- 2010年6月 (1)
- 2010年4月 (1)
- 2010年3月 (1)
- 2009年11月 (1)
- 2009年9月 (2)
- 2009年8月 (1)
- 2009年7月 (2)
- 2009年6月 (1)
- 2009年5月 (3)
- 2009年4月 (8)
- 2009年3月 (5)
- 2009年2月 (4)
- 2009年1月 (2)
- 2008年12月 (10)
- 2008年11月 (2)
- 2008年9月 (10)
- 2008年8月 (12)
- 2008年7月 (12)
- 2008年6月 (3)
- 2008年5月 (53)
文章分類
文章檔案
相冊
收藏夾
搜索
最新評論

- 1.?re: js 操作文件[未登錄]
- 00
- --00
- 2.?re: s:bean.jsp
- fdfdsa
- --dfasdf
- 3.?re: hibernate 常用標識生成器
- 藝達廣告歡迎您
- --藝達廣告
- 4.?re: linux mod_jk.so 下載[未登錄]
- 3Q!
- --me
- 5.?re: weblogic參數設置[未登錄]
- 垃圾
- --xx