Hibernate示例程序中的java.lang.NullPointerException

时间:2010-08-16 12:24:58

标签: java hibernate orm

我尝试运行hibernate的示例应用程序,它在运行时给出了一个错误:

  

log4j:WARN找不到logger(org.hibernate.cfg.Environment)的appender。
  log4j:WARN请正确初始化log4j系统   线程“main”java.lang.NullPointerException中的异常       at transaction.rollback();

这是在Main.java中:

public class Main {

public static void main(String[] args) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction transaction = null;
    try {
        transaction = session.beginTransaction();
        Address address = new Address("ABC", "Delhi", "TN", "110001");
        Student student = new Student("kumar", address);
        session.save(student);
        transaction.commit();
    } catch (HibernateException e) {
        transaction.rollback();
        e.printStackTrace();
    } finally {
        session.close();
    }

1 个答案:

答案 0 :(得分:1)