public static void testManyToOne(){ Student stu1 = new Student("小明","男"); Student stu2 = new Student("小红","女"); Grade grad1 = new Grade("java三班","java三班"); stu1.setGrade(grad1); stu2.setGrade(grad1); Session ses1 = HibernateUtil.getSession(); Transaction tran = ses1.beginTransaction(); ses1.save(stu1); ses1.save(stu2); ses1.save(grad1); tran.commit(); HibernateUtil.closeSession(ses1); }
原文地址:https://www.cnblogs.com/1446358788-qq/p/9375505.html
时间: 2024-10-08 14:07:45