为什么我Grade里的Se<Student>写对了的还是有空指针异常?
这是导包的问题?
这是导包的问题?
2015-10-28
package com.imooc.entity; import org.hibernate.Session; import org.hibernate.Transaction; import com.imooc.util.HibernateUtil; /* * 单向一对多关系(班级--》学生) */ public class Test { public static void main(String[] args) { add(); } //将学生添加到班级 public static void add() { Grade g = new Grade("java-1","java开发"); Student stu1 = new Student("张三","男"); Student stu2 = new Student("李四","女"); //如果希望在学生表中添加对应的班级编号,需要在班级中添加学生,简历关联关系 g.getStudents().add(stu1); g.getStudents().add(stu2); Session session = HibernateUtil.getSession(); Transaction tx = session.beginTransaction(); session.save(g); session.save(stu1); session.save(stu2); tx.commit(); HibernateUtil.closeSession(session); } }
举报