如果你是用hibernate.cfg.xml的话
生成session的方法应该是用以下这种文件
public static SessionFactory sessionFactory;
private static Configuration configuration;
static { try {
configuration = new Configuration(); sessionFactory = configuration.configure().buildSessionFactory();
} catch (Throwable ex) { throw new ExceptionInInitializerError(ex);
}
}

解决方案 »

  1.   

    sessionFactory = new Configuration().configure().buildSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    我就是用的这种方法啊!
    不知道是不是我配置什么地方不对啊!
      

  2.   

    getCurrentSession 不对
    用openSession 你再看下 hibernate api doc 对 openSession 和 getCurrentSession 的说明
      

  3.   

    谢谢各位仁兄,我改成了openSession就成功了,但是不知道为什么我昨天晚上也改成openSession就没有成功!呵呵!
    能解释一下openSession和getCurrentSession()的不同吗?
    我是根据Hibernate Reference Documentation里面的例子写的程序。