空指针异常???求解
十一月 09, 2016 9:17:33 上午 org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000230: Schema export complete
Exception in thread "main" java.lang.NullPointerException
at com.test.Test.add(Test.java:26)
at com.test.Test.main(Test.java:12)
package com.test;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.entity.*;
import com.util.HibernateUnit;
public class Test {
public static void main(String[] args){
add();
System.out.println("lallaaaaaa");
}
public static void add(){
Grade g = new Grade("java一班","java软件开发一班");
Student stu1 = new Student("张三丰","男");
Student stu2 = new Student("乔峰","男");
g.getStudent().add(stu1);
g.getStudent().add(stu2);
//获取会话对象
Session session = HibernateUnit.getSession();
Transaction tx = session.beginTransaction();
session.save(g);
session.save(stu1);
session.save(stu2);
tx.commit();
HibernateUnit.closeSession(session);
}
}