日期:2014-05-16 浏览次数:20404 次
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.
当前线程
Hibernate offers three methods of current session tracking. The "thread" based method is not intended for production use; it is merely useful for prototyping and tutorials such as this one. Current session tracking is discussed in more detail later on.
3个方法
?
A org.hibernate.Session
begins when the first call to getCurrentSession()
is made for the current thread. It is then bound by Hibernate to the
current thread. When the transaction ends, either through commit or
rollback, Hibernate automatically unbinds the org.hibernate.Session
from the thread and closes it for you. If you call getCurrentSession()
again, you get a new org.hibernate.Session
and can start a new unit of work.
新会话
?