Announcement Announcement Module
Collapse
No announcement yet.
Hibernate 4 open session AOP Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate 4 open session AOP

    I've read the Spring 3.1 reference that plain Hibernate style, sessionFactory.getCurrentSession() is recommended. The question is when to open and close the session. I know @Transactional does that, but it can't handle the following scenario:

    open session
    read something
    begin transaction 1
    write something
    commit transaction 1
    begin transaction 2
    write something
    commit transaction 2
    close session

    If the whole method is annotated with @Transactional, I can't separate 2 transactions. Is there any AOP utility to manage only the session (but not transaction) around method invocation? OpenSessionInViewInterceptor does not fit because my application is not a webapp.

  • #2
    I suggest a read of the reference guide especially the transaction chapter.

    You can still do manual transaction management by using either a TransactionTemplate or interact directly with a PlatformTransactionManager.

    Comment


    • #3
      Thanks Marten. My focus is not on transaction. I would like to know except @Transactional, is there any AOP utility to open a session and bind it to the session factory's current session?

      Comment


      • #4
        Why would you want to open an new session whereas a single session is perfectly capable of managing multiple transactions?!

        But to directly answer your question no there isn't....

        Comment

        Working...
        X