Announcement Announcement Module
Collapse
No announcement yet.
Session Behavior with Spring Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      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.

      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.

      Comment

      Working...
      X