通过一方设置与多方的关系时始终提示空对象异常,求指教,谢谢各位大神
public static void add(){
Grade g=new Grade("java","软件开发一班");
Student stu2=new Student("张三","男");
Student stu1=new Student("穆女生","女");
//班级中添加学生建立关联关系
g.getStudents().add(stu1);
g.getStudents().add(stu2);
Session session=HibernateUtil.getSession();
Transaction tx=session.beginTransaction();
session.save(g);
// stu1.setGrade(g);
// stu2.setGrade(g);
session.save(stu1);
session.save(stu2);
tx.commit();
HibernateUtil.closeSession(session);
}
执行代码在建立关联关系处总是提示空指针异常