using current_session_context_class property hibernate 3 hibernate 4

家住魔仙堡 提交于 2019-11-30 08:59:22

It depends on the version of spring but in general messing around with that property whilst using Spring must be avoided (unless you use JTA for transactions then you need to configure this).

As of Hibernate 3.1 there is something called contextual sessions and for that hibernate provides the CurrentSessionContext interface. There are several implementations for this (and thread is short for ThreadLocalSessionContext). Spring has its own implementation of this interface the SpringSessionContext class.

Spring by default sets the property to Springs implementation of the CurrentSessionContext, when this is set to something else (other then JTA) this will break springs ability to manage the hibernate session (and thus the transaction).

Now in older versions of spring (and I assume you also upgraded Spring to be able to use hibernate) combined with hibernate 3 there was some other trickery involved regarding getting the session (due to backwards compatibility with older 3.x versions of hibernate). This made Spring less depended on the value of that property. (Spring created a proxy for the SessionFactory and basically intercepted the getSession method to be able to manage the session).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!