您的位置:首页 > 其它

Hibernate级联查询实体关系映射

2016-05-22 13:05 453 查看

Hibernate 实体关系映射




















4. 使用 MyEclipse 的 的 反向 工程 向导 生成 关系

DB Browser 中的表中右击-->Hibernate reverse Engineering...








选择所选择表的主键生成方式,如图中进行配置,选择 native:






在表有关系中选择“Include referenced tables(A->B)”和"Include referencing

tables(a<-B)"两个复选框;

选择自动增长的主键表的 id 的生成方式为 native;

点击完成,即可完成操作。






对 对 生成 的 映射 进行


public static void main(String[] args) {
Session session = HibernateSessionFactory.getSession();
session.beginTransaction();
List<Student> list = session.createQuery("from Student").list();
for(Student stu:list){
System.out.println(" 学号:"+stu.getStunumber()+" ,姓名:"+stu.getStuname()+
": , 系院编码: "+stu.getDepartment().getBm()+": , 系院名称: "+stu.getDepartment().getMc());
}
session.close();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: