建立双向一对多关系,既可以由一方查询多方信息,同样可以由多方查询一方信息
demo:
//查询学生所在班级 public static void showGidByStudent(){ Session sess1 = HibernateUtil.getSession(); Student stu1 = (Student) sess1.get(Student.class, 1); System.out.println("学生姓名为:"+stu1.getSname()); Grade grad1 = stu1.getGrade(); System.out.println("该学生班级为:"+grad1.getGid()); HibernateUtil.closeSession(sess1); }
原文地址:https://www.cnblogs.com/1446358788-qq/p/9376475.html
时间: 2024-10-08 14:07:50