Hibernate - Session Factory opensession & getcurrentsession

SessionFacoty.openSession():

  • It always create a new session object.
  • You need to explicitly flush and close session object.
  • You no need to configure any property to call this method.
SessionFactory.getCurrentSession():
  • It create new session if not exists, else use the same session which is in current hibernate context.
  • You no need to flush and close. Internally Hibernate will take care.
  • You need to configure property,
       "hibernate.current_session_context_class"

<session-factory>
    <property name="hibernate.current_session_context_class" >
    </property>
</session-factory>

Comments

Popular posts from this blog

How to set Java Object into JaxBElement ?

GitLab