-
In the sessionfactory configuration file of SSH2
-
Set hibernate. current_session_context_class to org. springframework. Orm. hibernate3.springsessioncontext (default value)
-
And apply spring to manage transactions.
-
If it is <prop key = "hibernate. current_session_context_class"> thread </prop>, an exception is reported,
-
In the source code of spring class localsessionfactorybean
-
In method buildsessionfactory
- If (isexposetransactionawaresessionfactory () {<br/> // set hibernate 3.1 + currentsessioncontext implementation, <br/> // providing the spring-managed session as current session. <br/> // can be overridden by a custom value for the corresponding hibernate property. <br/> config. setproperty (<br/> environment. current_session_context_class, springsessioncontext. class. getname (); <br/>}< br/> If (this. jtat Ransactionmanager! = NULL) {<br/> // set spring-provided JTA transactionmanager as Hibernate property. <br/> config. setproperty (<br/> environment. transaction_strategy, jtatransactionfactory. class. getname (); <br/> config. setproperty (<br/> environment. transaction_manager_strategy, localtransactionmanagerlookup. class. getname (); <br/>}< br/> else {<br/> // makes the hibernate session aware of the presence of a spring-managed transaction. <br/> // also sets connection release mode to on_close by default. <br/> config. setproperty (<br/> environment. transaction_strategy, springtransactionfactory. class. getname (); <br/>}
-
Set
-
Hibernate. current_session_context_class is set to org. springframework. Orm. hibernate3.springsessioncontext
Springsessioncontext
Implementation of hibernate 3.1's currentsessioncontext interface that
Delegates to spring's sessionfactoryutils for providing a spring-managed current
Session.
Used by spring'sLocalSessionFactoryBean
When told to expose a transaction-aware sessionfactory. This is the default
Of Spring 2.5.
This currentsessioncontext implementation can also be specified in custom
Sessionfactory setup through the "hibernate. current_session_context_class"
Property, with the fully qualified name of this class as value.
-
public class SpringSessionContext
-
Extends object
-
Implements org. hibernate. Context. currentsessioncontext
Implementation of hibernate 3.1's currentsessioncontext Interface
That delegates to spring's sessionfactoryutils for providing
Spring-managed current session.
Used by spring'sLocalSessionFactoryBean
When told to expose
Transaction-aware sessionfactory. This is the default as of spring 2.5.
This currentsessioncontext implementation can also be specified in custom
Sessionfactory setup through the "hibernate. current_session_context_class"
Property, with the fully qualified name of this class as value.