Announcement Announcement Module
No announcement yet.
Are Session Automatically Closed when Exception Occurs Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Are Session Automatically Closed when Exception Occurs

    Hi all,
    I am using Declarative Transactional Support in spring,basically all the service classes are annotated with @Transactional and in code I am using this
    Session session=getHibernateTemplate().getSessionFactory().getCurrentSession();
    Now in one of the DAO method Exception is thrown deliberately if object is not found in DB. Can somebody please let me know whether it would result in automatic closing of session or I need to close the session manually when some exception is thrown by DAO layer ?

  • #2
    It will (that is the whole point of declarative tx management isn't it).

    However your way of getting the current session isn't the recommended way. Avoid the use of HibernateTemplate/HibernateDaoSupport and simply inject the SessionFactory directly.