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:13
H2O
阅读(338)
评论(0)
编辑
收藏
所属分类:
hibernate
人与卡(身份证)---一对一
package
com.yz.pojos;
public
class
Person
{
private
Integer pid;
private
String pname;
private
Integer page;
//
一个人对应一张卡
private
Card cards
=
new
Card();
public
Person()
{
}
public
Person(Integer pid, String pname, Integer page, Card cards)
{
super
();
this
.pid
=
pid;
this
.pname
=
pname;
this
.page
=
page;
this
.cards
=
cards;
}
public
Integer getPid()
{
return
pid;
}
public
void
setPid(Integer pid)
{
this
.pid
=
pid;
}
public
String getPname()
{
return
pname;
}
public
void
setPname(String pname)
{
this
.pname
=
pname;
}
public
Integer getPage()
{
return
page;
}
public
void
setPage(Integer page)
{
this
.page
=
page;
}
public
Card getCards()
{
return
cards;
}
public
void
setCards(Card cards)
{
this
.cards
=
cards;
}
}
<?
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.Person"
table
="person"
catalog
="ssh"
>
<
id
name
="pid"
type
="java.lang.Integer"
>
<
column
name
="pid"
/>
<
generator
class
="native"
/>
</
id
>
<
property
name
="pname"
type
="java.lang.String"
>
<
column
name
="pname"
length
="32"
not-null
="true"
/>
</
property
>
<
property
name
="page"
type
="java.lang.Integer"
>
<
column
name
="page"
not-null
="true"
/>
</
property
>
<!--
name:Card的属性
Class 属性所属的类
property-ref:一张卡对应一个人,那个人,Card类里所对应的人person属性
cascade=all 级联更新和删除
-->
<
one-to-one
cascade
="delete"
name
="cards"
class
="com.yz.pojos.Card"
property-ref
="person"
></
one-to-one
>
</
class
>
</
hibernate-mapping
>
package
com.yz.pojos;
import
javax.xml.registry.infomodel.PersonName;
/** */
/**
* Card entity.
*
*
@author
MyEclipse Persistence Tools
*/
public
class
Card
implements
java.io.Serializable
{
//
Fields
private
Integer cid;
//
一张卡对应一个人
private
Person person;
private
String cname;
//
Constructors
/** */
/**
default constructor
*/
public
Card()
{
}
/** */
/**
full constructor
*/
public
Card(Person person, String cname)
{
this
.person
=
person;
this
.cname
=
cname;
}
//
Property accessors
public
Integer getCid()
{
return
this
.cid;
}
public
void
setCid(Integer cid)
{
this
.cid
=
cid;
}
public
Person getPerson()
{
return
this
.person;
}
public
void
setPerson(Person person)
{
this
.person
=
person;
}
public
String getCname()
{
return
this
.cname;
}
public
void
setCname(String cname)
{
this
.cname
=
cname;
}
}
<?
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.Card"
table
="card"
catalog
="ssh"
>
<
id
name
="cid"
type
="java.lang.Integer"
>
<
column
name
="cid"
/>
<
generator
class
="native"
/>
</
id
>
<
many-to-one
name
="person"
class
="com.yz.pojos.Person"
fetch
="select"
>
<
column
name
="pid"
/>
</
many-to-one
>
<
property
name
="cname"
type
="java.lang.String"
>
<
column
name
="cname"
length
="32"
/>
</
property
>
</
class
>
</
hibernate-mapping
>
新用户注册
刷新评论列表
只有注册用户
登录
后才能发表评论。
网站导航:
博客园
IT新闻
Chat2DB
C++博客
博问
管理
相关文章:
hibernate一对一完美版
hibernate关系映射(一对一)
hibernate关系映射(多对多)
hibernate关系映射(一对多)
评论排行榜
阅读排行榜
posts - 0, comments - 21, trackbacks - 0, articles - 101
Copyright © H2O