Results 1 to 5 of 5

Thread: Hibernate session and multiple transactions

  1. #1
    Join Date
    Aug 2004
    Location
    Eagan, MN
    Posts
    11

    Default Hibernate session and multiple transactions

    It seems that a new session is created at the beginning of each new transaction and closed at the end. Is it possible to share the same session
    if transactions are nested? Something like:

    // ISOLATION_REQUIRED
    doBusinessA()
    {
    A obj1 = loadById(3);

    serviceA.doPart1(obj1) // ISOLATAION_REQUIRES_NEW

    ....
    }

    class A {

    // ISOLATAION_REQUIRES_NEW
    doPart1(A obj)
    {
    // setting values....
    getHibernateTemplate().save(obj)
    }

    }

  2. #2
    Join Date
    Aug 2004
    Location
    Columbus, OH, USA
    Posts
    133

    Default

    How are you managing your sessons? If you use the OpenSessionInViewFilter, the session's lifespan will be bound to the request/response cycle, not a single transaction.

  3. #3
    Join Date
    Aug 2004
    Location
    Eagan, MN
    Posts
    11

    Default

    The session is managed by HibernateTransactionManager. I'm using source-annonations for transaction demarcation. A transaction is started
    by doBusiness().

    Quote Originally Posted by smccrory
    How are you managing your sessons? If you use the OpenSessionInViewFilter, the session's lifespan will be bound to the request/response cycle, not a single transaction.

  4. #4
    Join Date
    Aug 2004
    Location
    Columbus, OH, USA
    Posts
    133

    Default

    Then no, your sessions will not live outside of the doBusiness() methods and thus will not be recycled from one business call/transaction to the next. If you want this, I recommend moving session management to OpenSessionInViewFilter.

  5. #5
    Join Date
    Aug 2004
    Location
    Eagan, MN
    Posts
    11

    Default

    I probably didn't explain my problem very well. I only want to share
    the session created by doBusiness1() inside itself. This is what I want:

    doBusiness1()
    {
    - new hibernate session (by spring)
    - new transaction (by spring)

    - look up a hibernate object A
    - doPartA(A)
    {
    - new transaction
    - use above session <= looks like Spring doesnt do this
    - make changes to A
    - save A
    - commit transaction
    }

    - commit transaction
    - close session
    }

    Is that more clear?




    Quote Originally Posted by smccrory
    Then no, your sessions will not live outside of the doBusiness() methods and thus will not be recycled from one business call/transaction to the next. If you want this, I recommend moving session management to OpenSessionInViewFilter.

Similar Threads

  1. Replies: 7
    Last Post: Apr 18th, 2007, 09:50 AM
  2. JTA and multiple hibernate session factories
    By juan110470 in forum Data
    Replies: 7
    Last Post: Jan 18th, 2007, 03:16 AM
  3. Replies: 2
    Last Post: Mar 15th, 2005, 07:46 PM
  4. Replies: 8
    Last Post: Sep 23rd, 2004, 01:12 AM
  5. Replies: 7
    Last Post: Aug 21st, 2004, 03:42 AM

Posting Permissions

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