Results 1 to 3 of 3

Thread: Session Behavior with Spring

  1. #1
    Join Date
    Apr 2008
    Posts
    8

    Default Session Behavior with Spring

    I have an OpenSessionInViewInterceptor in my application, And a service class method calling DAO methods. All my DAO methods are transactional with PROPOGATION_REQUIRED.

    Lets say there are about 10 calls to different dao methods inside a single service method, but the service method is not transactional.

    I assume since OpenSessionInViewInterceptor is in action. A single session will be used and transactions are wrapped around each dao method call. But it is not consistent. HibernateTransactionManager randomly creates new sessions for some method calls and for some it doesnt

    See my log
    Code:
    -Found thread-bound Session [org.hibernate.impl.SessionImpl@188e490] for Hibernate transaction
    - Creating new transaction with name [com.bmc.dao.MemberDAO.findBrokersDfltMember]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
    - Preparing JDBC Connection of Hibernate Session [org.hibernate.impl.SessionImpl@188e490]
    
    
    
    -Found thread-bound Session [org.hibernate.impl.SessionImpl@188e490] for Hibernate transaction
    - Creating new transaction with name [com.bmc.dao.PlanDAO.getPlan]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
    - Preparing JDBC Connection of Hibernate Session [org.hibernate.impl.SessionImpl@188e490]
    
    
    -Found thread-bound Session [org.hibernate.impl.SessionImpl@188e490] for Hibernate transaction
    - Creating new transaction with name [com.bmc.dao.MemberDAO.saveMemberChange]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
    - Opened new Session [org.hibernate.impl.SessionImpl@3457f1] for Hibernate transaction
    - Preparing JDBC Connection of Hibernate Session [org.hibernate.impl.SessionImpl@3457f1]
    In the third method call i dont understand why it needs a new session, all of these methods are declared as PROPOGATION_REQUIRED

    Thanks in advance

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

    Default

    First off all the service layer should really be the transactional boundary if you have 1 service call making 10 dao calls and the 8th fails you already have 7 commits leaving your database in a undesired state.

    Regarding the behavior it depends. The OSIVF/-I can be configured to use a single session or multiple session. So it basically depends on your configuration if you have 1 or multiple sessions.
    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
    Apr 2008
    Posts
    8

    Default

    Thats fine for the business logic. I cant make the service layer transactional because each one of these transactions processes large amounts of data.

    My OSIVF is configured to use single session, I assume the way it should work is one session gets opened up in OSIVI and each transaction uses the same session does the work(updates/inserts) flushes the session and commits it. Them it doesnt really close the session there by leaving the next transaction to reuse it.

    It works the way i described for a few transactions then all of a sudden it starts a new transaction.

    Quote Originally Posted by Marten Deinum View Post
    First off all the service layer should really be the transactional boundary if you have 1 service call making 10 dao calls and the 8th fails you already have 7 commits leaving your database in a undesired state.

    Regarding the behavior it depends. The OSIVF/-I can be configured to use a single session or multiple session. So it basically depends on your configuration if you have 1 or multiple sessions.

Posting Permissions

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