8.综合一点的映射配置小示例
drop table tb_orderitem cascade constraint;
create table tb_user
(id integer primary key,
userName varchar2(20) not null,
userPwd varchar2(20) not null,
regDate date default sysdate
);
insert into tb_user values(1,'jack','520',sysdate);
insert into tb_user values(2,'rose','520',sysdate);
insert into tb_user values(3,'jinkun','520',sysdate);
insert into tb_user values(4,'dinghui','520',sysdate);
create table tb_product
( id integer primary key,
proName varchar2(50) not null,
price number(10,2) default 0,
picture varchar2(100),
discription varchar2(200)
);
insert into tb_product values(1,'电脑',5200,'images/computer.jpg','好电脑啊好电脑!');
insert into tb_product values(2,'玫瑰',52,'images/flower.jsp','好花啊好花!');
insert into tb_product values(3,'衣服',520,'images/clothing.jsp','好衣服啊好衣服!');
create table tb_order
( id integer primary key,
userId integer references tb_user(id),
amount number(10,2) default 0,
datetime date default sysdate
);
insert into tb_order values(1,2,104,sysdate);
create table tb_orderItem
(id integer primary key,
orderId integer references tb_order(id),
proId integer references tb_product(id) ,
procount integer not null,
balance number(10,2) default 0
);
insert into tb_orderitem values(1,1,2,2,104);
配置说明
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="edu.yzu.entity">
<class name="User" table="tb_user">
<id name="id">
<generator class="increment" />
</id>
<property column="userName" name="userName" type="string" />
<property column="userpwd" name="userPwd" type="string" />
<property column="regDate" name="regDate" type="date" />
</class>
<class name="Product" table="tb_product">
<id column="id" name="id">
<generator class="increment" />
</id>
<property column="proName" name="proName" type="string" />
<property column="price" name="price" type="double" />
<property column="picture" name="picture" type="string" />
<property column="discription" name="discription" type="string" />
</class>
<class name="Order" table="tb_Order">
<id column="id" name="id">
<generator class="increment" />
</id>
<many-to-one name="user" column="userId" lazy="false" />
<set name="orderItems" inverse="true" cascade="all-delete-orphan"
lazy="false">
<key column="orderId"></key>
<one-to-many class="OrderItem" />
</set>
<property name="amount" type="double" column="amount" />
<property name="datetime" type="date" column="datetime" />
</class>
<class name="OrderItem" table="tb_orderItem">
<id name="id" column="id">
<generator class="increment" />
</id>
<many-to-one name="order" column="orderId" />
<many-to-one name="product" column="proId" lazy="false" />
<property name="balance" type="double" column="balance" />
<property name="proCount" type="integer" column="proCount" />
</class>
</hibernate-mapping>