Results 1 to 4 of 4

Thread: Hibernate 4 open session AOP

  1. #1
    Join Date
    Feb 2012
    Posts
    7

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Feb 2012
    Posts
    7

    Default

    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?

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    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....
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

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