为啥我的总是出现Exception in thread "main" java.lang.NullPointerException at com.msl.test.test1.main(test1.java:25)
package com.msl.test;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.msl.entity.Grade;
import com.msl.entity.Student;
import com.msl.util.HibernateSessionFactory;
public class test1 {
public static void main(String[] args) {
Transaction tx=null;
Session session=null;
try {
Grade g=new Grade("java1","java一班学习");
Student stu1=new Student("幕女神","女");
Student stu2=new Student( "小木木","男");
g.getStudents().add(stu1);
g.getStudents().add(stu2);
session=HibernateSessionFactory.getSession();
tx=session.getTransaction();
session.save(g);
session.save(stu1);
session.save(stu2);
tx.commit();
HibernateSessionFactory.closeSession();
} catch (HibernateException e) {
// TODO: handle exception
tx.rollback();
}
}
}