JDBC 和 ORM

Hibernate

Session, Transaction, Connection. What's the difference?

When the seesion=sessionFactory.getCurrentSession will close?

  • One Transaction per session. When transaction was committed, the session will be closed.If it is in tomcat, the current Thread will be returned to thread pool. But the session can be closed successfully, even the corresponding thread is still live.
  • By default, the hibernate CurrentSessionContext is ThreadLocalSessionContext. The so called getCURRENTSession, the CURRENT means the session associated with current thread.
  • If you use sessionFactory.openSession, you have to manage/maintain/close this session by yourself.

results matching ""

    No results matching ""