import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import cn.jbit.houserent.entity.District;
import cn.jbit.houserent.entity.Street;
public class test2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
District district = new District();
Street street1 = new Street();
Street street2 = new Street();
Street street3 = new Street();
district.setName("丰台");
street1.setName("广安路");
street1.setDistrict(district);
street2.setName("大红门路");
street2.setDistrict(district);
street3.setName("南苑路");
street3.setDistrict(district);
SessionFactory sessionFactory = null;
Session session = null;
Transaction tx= null;
try{
sessionFactory =
new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
tx= session.beginTransaction();
session.save(street1);
session.save(street2);
session.save(street3);
session.save(district);
tx.commit();
}catch (HibernateException e) {
tx.rollback();
e.printStackTrace();
} finally{
session.close();
sessionFactory.close();
}
}
}
控制台提示
Exception in thread "main" java.lang.NullPointerException
at test2.main(test2.java:83)
------最佳解决方案--------------------
test2.java:83
83行指的上面的哪一行。。。
------其他解决方案--------------------
楼主代码没贴全
怀疑是以下方法有问题
sessionFactory = new Configuration().configure()
.buildSessionFactory();
session = sessionFactory.openSession();
------其他解决方案--------------------
test2.java:83
83行指的上面的哪一行。。。
------其他解决方案--------------------
sessionFactory =
new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
初步怀疑这里有问题。
------其他解决方案--------------------
该回复于2012-09-13 09:51:30被版主删除
------其他解决方案--------------------
用的是什么插件啊 把jar包给了在说
------其他解决方案--------------------
sessionFactory =
new Configuration().configure().buildSessionFactory();
跟一下看