欢迎来到天天文库
浏览记录
ID:6363082
大小:1012.79 KB
页数:53页
时间:2018-01-11
《hibernate_关联关系映射配置》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Hibernate关联关系映射配置2一、一对一单向外键关联:21.1目录结构21.2Annotation方式21.3XML方式41.4Hibernate配置文件7二、一对一双向外键关联72.1Annotation方式72.2XML方式9三、一对一单向主键关联(不重要)123.1Annotation方式123.2XML方式14四、一对一双向主键关联(不重要)164.1Annotation方式163.2XML方式19五、组件映射215.1Annotation方式215.2XML方式23六、多对一单向关联256.1Annotation方式256.2XML方式27七、一对多单向关联29537.1An
2、notation方式297.2XML方式31八、一对多、多对一双向关联348.1Annotation方式348.2XML方式36九、多对多单向关联398.1Annotation方式398.2XML方式41十、多对多双向关联448.1Annotation方式448.2XML方式4653Hibernate关联关系映射配置一、一对一单向外键关联:1.1目录结构图1-1目录结构图1.2Annotation方式1.2.1类图图1-2类关联关系图1.2.2数据库表结构53图1-3数据库表结构图1.2.3实体类packagecom.rongqq.hibernate3.annotation.entity;i
3、mportjava.math.BigDecimal;importjavax.persistence.Column;importjavax.persistence.Entity;importjavax.persistence.GeneratedValue;importjavax.persistence.GenerationType;importjavax.persistence.Id;importjavax.persistence.OneToOne;importjavax.persistence.SequenceGenerator;@Entity(name="H_HUSBAND_")@Sequ
4、enceGenerator(name="husband_seq_gene",sequenceName="HUSBAND_SEQ",allocationSize=1)publicclassHusband{privateBigDecimalid;privateStringname;privateWifewife;@Id@Column(precision=4,scale=0)@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="husband_seq_gene")publicBigDecimalgetId(){returnid;}@
5、Column(length=30)publicStringgetName(){returnname;}@OneToOne//@JoinColumn(name="wife_id")//不写也没问题,自动生成的字段也叫wife_idpublicWifegetWife(){returnwife;}publicvoidsetId(BigDecimalid){53this.id=id;}publicvoidsetName(Stringname){this.name=name;}publicvoidsetWife(Wifewife){this.wife=wife;}}packagecom.rongqq.
6、hibernate3.annotation.entity;importjava.math.BigDecimal;importjavax.persistence.Column;importjavax.persistence.Entity;importjavax.persistence.GeneratedValue;importjavax.persistence.GenerationType;importjavax.persistence.Id;importjavax.persistence.SequenceGenerator;@Entity(name="H_WIFE_")@SequenceGe
7、nerator(name="wife_seq_gene",sequenceName="WIFE_SEQ")publicclassWife{privateBigDecimalid;privateStringname;@Id@Column(precision=4)@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="wife_seq_gene")p
此文档下载收益归作者所有