H2O
BlogJava
首页
新随笔
联系
聚合
管理
随笔分类
java
(rss)
职业生涯o 0O
(rss)
文章分类
ajax(6)
(rss)
css(5)
(rss)
DataBase(9)
(rss)
ejb
(rss)
EXT(1)
(rss)
hibernate(4)
(rss)
java(14)
(rss)
javascript(13)
(rss)
spring(1)
(rss)
Spring+Struts+Hibernate整合(4)
(rss)
struts(4)
(rss)
webwork
(rss)
职业生涯规划(1)
(rss)
那一天o 0 O(1)
(rss)
面试(1)
(rss)
文章档案
2013年10月 (1)
2013年9月 (30)
2013年8月 (7)
2012年2月 (1)
2011年9月 (1)
2011年8月 (1)
2010年10月 (1)
2009年10月 (5)
2009年9月 (4)
2009年8月 (2)
2009年7月 (2)
2009年6月 (4)
2009年5月 (7)
2009年3月 (3)
2008年12月 (1)
2008年11月 (3)
2008年10月 (8)
2008年9月 (12)
2008年8月 (8)
相册
程序相关
最新随笔
1. Debian / Ubuntu ---support UTF-8 locale/encoding
2. Firefox Latest version
3. 重写 FastJson 属性过滤器
4. freeradius for pptp
5. Configuring Wildcard AlphaSSL from Centrio Host
6. SSL
7. some errors occured in complie firefox source
8. checking for libnotify >= 0.4... Package libnotify was not found in the pkg-config search path.
9. modify max_connections on mysql
10. centos encoding
最新评论
1. re: js获取textarea中输入文本的本选择内容
333333
--333
2. re: 小毅原创---struts+spring+hibernate整合小例子
俄方
--预报呢
3. re: some errors occured in complie firefox source
Thank you very very much for this post!
jelz
--Jelz
4. re: some errors occured in complie firefox source
Thank you very much for this post!
Jelz
--Jelz
5. re: Ibatis之LIKE用法[未登录]
如果用'%$note$%'会造成sql注入的漏洞,使用拼接字符串的方法不错
--KANG
hibernate关系映射(一对多)
Posted on 2008-08-21 12:00
H2O
阅读(338)
评论(0)
编辑
收藏
所属分类:
hibernate
客户与订单---一对多
package
com.yz.pojos;
import
java.util.HashSet;
import
java.util.Set;
/** */
/**
* Customer generated by MyEclipse Persistence Tools
*/
public
class
Customer
implements
java.io.Serializable
{
//
Fields
private
Integer cid;
private
String name;
private
String addr;
//
一个客户可以有多个订单,一对多关系。但是一个客户不能有重复的订单,所以用Set集合,set集合不允许出现重复值
//
set集合反映了一个客户的所有订单
private
Set orderses
=
new
HashSet(
0
);
//
Constructors
/** */
/**
default constructor
*/
public
Customer()
{
}
/** */
/**
minimal constructor
*/
public
Customer(String name)
{
this
.name
=
name;
}
/** */
/**
full constructor
*/
public
Customer(String name, String addr, Set orderses)
{
this
.name
=
name;
this
.addr
=
addr;
this
.orderses
=
orderses;
}
//
Property accessors
public
Integer getCid()
{
return
this
.cid;
}
public
void
setCid(Integer cid)
{
this
.cid
=
cid;
}
public
String getName()
{
return
this
.name;
}
public
void
setName(String name)
{
this
.name
=
name;
}
public
String getAddr()
{
return
this
.addr;
}
public
void
setAddr(String addr)
{
this
.addr
=
addr;
}
public
Set getOrderses()
{
return
this
.orderses;
}
public
void
setOrderses(Set orderses)
{
this
.orderses
=
orderses;
}
}
<?
xml version="1.0" encoding="utf-8"
?>
<!
DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
>
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<
hibernate-mapping
>
<
class
name
="com.yz.pojos.Customer"
table
="customer"
lazy
="false"
>
<
id
name
="cid"
type
="java.lang.Integer"
>
<
column
name
="cid"
/>
<
generator
class
="native"
/>
</
id
>
<
property
name
="name"
type
="java.lang.String"
>
<
column
name
="name"
length
="20"
not-null
="true"
/>
</
property
>
<
property
name
="addr"
type
="java.lang.String"
>
<
column
name
="addr"
length
="50"
/>
</
property
>
<!--
set集合保存该客户所有的订单,通过键cid查找订单
-->
<
set
name
="orderses"
lazy
="true"
cascade
="delete"
inverse
="true"
>
<
key
>
<
column
name
="cid"
not-null
="true"
/>
</
key
>
<
one-to-many
class
="com.yz.pojos.Orders"
/>
</
set
>
</
class
>
</
hibernate-mapping
>
订单与客户---多对一
package
com.yz.pojos;
import
java.util.Date;
/** */
/**
* Orders generated by MyEclipse Persistence Tools
*/
public
class
Orders
implements
java.io.Serializable
{
//
Fields
private
Integer oid;
//
在多个订单中,每个订单只能属于一个客户,属于 多对一关系,所以要告诉每个订单属于哪一个客户对象
private
Customer customer;
private
Date odate;
//
Constructors
/** */
/**
default constructor
*/
public
Orders()
{
}
/** */
/**
full constructor
*/
public
Orders(Customer customer, Date odate)
{
this
.customer
=
customer;
this
.odate
=
odate;
}
//
Property accessors
public
Integer getOid()
{
return
this
.oid;
}
public
void
setOid(Integer oid)
{
this
.oid
=
oid;
}
public
Customer getCustomer()
{
return
this
.customer;
}
public
void
setCustomer(Customer customer)
{
this
.customer
=
customer;
}
public
Date getOdate()
{
return
this
.odate;
}
public
void
setOdate(Date odate)
{
this
.odate
=
odate;
}
}
<?
xml version="1.0" encoding="utf-8"
?>
<!
DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
>
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<
hibernate-mapping
>
<
class
name
="com.yz.pojos.Orders"
table
="orders"
catalog
="ssh"
>
<
id
name
="oid"
type
="java.lang.Integer"
>
<
column
name
="oid"
/>
<
generator
class
="native"
/>
</
id
>
<!--
订单与客户多对一,告诉订单所关联的客户是谁
-->
<
many-to-one
name
="customer"
class
="com.yz.pojos.Customer"
fetch
="select"
>
<
column
name
="cid"
not-null
="true"
/>
</
many-to-one
>
<
property
name
="odate"
type
="java.util.Date"
insert
="true"
>
<
column
name
="odate"
length
="19"
not-null
="true"
/>
</
property
>
</
class
>
</
hibernate-mapping
>
新用户注册
刷新评论列表
只有注册用户
登录
后才能发表评论。
网站导航:
博客园
IT新闻
Chat2DB
C++博客
博问
管理
相关文章:
hibernate一对一完美版
hibernate关系映射(一对一)
hibernate关系映射(多对多)
hibernate关系映射(一对多)
评论排行榜
阅读排行榜
posts - 0, comments - 21, trackbacks - 0, articles - 101
Copyright © H2O