Hibernate级联查询实体关系映射

Hibernate  实体关系映射


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

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

扫描二维码关注公众号,回复: 9081068 查看本文章

选择所选择表的主键生成方式,如图中进行配置,选择 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();
}
发布了269 篇原创文章 · 获赞 2 · 访问量 6991

猜你喜欢

转载自blog.csdn.net/zhupengqq1/article/details/104206304