1. 程式人生 > >SpringMVC 4.0整合Hibernate 4如何使用sessionFactory.getCurrentSession()方法

SpringMVC 4.0整合Hibernate 4如何使用sessionFactory.getCurrentSession()方法

這幾天在學習Spring4MVC整合Hibernate4,其中遇到了一個比較大的困惑,就是呼叫sessionFactory的getCurrentSession方法時,session不為空,但是sql語句就是不執行,在Hibernate文件中有這麼一段話Remember that we switched the configuration option for this mechanism to "thread" in our src/main/resources/hibernate.cfg.xml? Due to that setting, the context of a current unit of work is bound to the current Java thread that executes the application.,自然似乎配置了<prop key="hibernate.current_session_context_class">thread</prop>這一項之後getCurrentSession就可以工作了。結果不然,配置了這段內容之後,呼叫Hibernate操作時候,則會提示xxxx