Results 1 to 1 of 1

Thread: @Transactional behaviour

  1. #1
    Join Date
    Jan 2009
    Posts
    9

    Default @Transactional behaviour

    Hi All,

    I have a core library which exposes multiple services. Whenever these services call a Dao to update the database I've marked them with @transactional . However, if they just read the database through the Dao, I leave them with no annotation.

    I didn't have any problem when I used HibernateDaoSupport/HibernateTemplate. When I wanted to use plain hibernate 3 api I am hitting an issue.

    1) HibernateTemplate uses getSession(SessionFactory, allowCreate) in SessionFactoryUtils to get a session. So, even if I don't mark a service as transactional, I get a session back.

    2) In the new approach (plain hibernate 3 api), I checked that general opinion is to use sessionFactory.getCurrentSession() which returns a session only if transaction is there else returns an illegal state exception.

    My question is, can I use SessionFactoryUtils.getSession(sessionFactory,true ) to get the current session? It looks like it works. But, do you see any issue in doing this..

    The alternative is I need to mark all my non-commiting serivces as "@transactional" which is a lot of change.
    Last edited by vij123456; Apr 6th, 2009 at 11:05 AM. Reason: More Clarity

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •