我想问你一件事,为什么要尝试使用“ OpenSession”方法?
public static Session getSession() throws HibernateException { Session sess = null; try { sess = sessionFactory.getCurrentSession(); } catch (org.hibernate.HibernateException he) { sess = sessionFactory.openSession(); } return sess;}您不必调用
openSession(),因为
getCurrentSession()method始终返回当前会话(如果已将其配置为,则返回Thread)。
我明白了!…您必须在hibernate.cfg.xml文件中指定当前上下文
它应该是:
<property name="hibernate.current_session_context_class">thread</property>



