using current_session_context_class property hibernate 3 hibernate 4

后端 未结 1 1620
执念已碎
执念已碎 2020-12-31 11:30

I have an application with Spring and Hibernate3 running well in production. Following is the config for session factory in Spring\'s applicationContext.xml

         


        
1条回答
  •  臣服心动
    2020-12-31 12:09

    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).

    0 讨论(0)
提交回复
热议问题