<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
打开自动线程管理。
What does sessionFactory.getCurrentSession()
do? First, you can call it as many times and anywhere you like once you get hold of your org.hibernate.SessionFactory
. The getCurrentSession()
method always returns the "current" unit of work. 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.