首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

用注脚的方式配置hibernate po对象关系

2012-08-26 
用注解的方式配置hibernate po对象关系1.一对多 这个我们很容易想到的 mappedBy的意思是关联外键 如下面的

用注解的方式配置hibernate po对象关系

1.一对多 这个我们很容易想到的 mappedBy的意思是关联外键 如下面的意思是:Employee 中的外键是Employee中的department 默认是与主键关联 如果我们在一端不写则会生成一个中间表。employee_department 因为是由两个主键来维护。 @Entity public class Employee{@id@GeneratedValue(strategy=GenerationType.AUTO)private int empid;private String ename;@ManyToOneprivate Department department; // get set 省略}@Entitypublic class Department{@Id@GeneratedValue(strategy=GenerationType.AUTO)private int id;private String dname;private String location;@OneToMany(mappedBy="department")private Set<Employee> employees=new HashSet<Employee>();//get set 方法省略}--------------------------2.多对多 多对多会生成中间表,而中间表若含有别的字段则没有办法操作,一般使用中我们将其分为两个一对多.

热点排行