Announcement Announcement Module
Collapse
No announcement yet.
Hibernate load causes table lock error for multiple threads Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate load causes table lock error for multiple threads

    Hi all,

    I have recently begun using Spring and Hibernate in combination, mainly to load objects from the database. The load works fine, except when attempting to load the same instance (same primary key) from multiple threads. A locking error (could not position within a table...) is thrown in some cases. The thing is, in this case, I'm only looking to read the data - this is not an object I need to be able to update. I attempted to call the load() method with LockMode.READ, but that had no effect.

    Is there a setting in the Hibernate config xml that might tell Hibernate the correct locking strategy? Is there something perhaps in the datasource setup to set the lock mode to wait? Will I ever find true happiness?

    Any help with these and other pressing questions is appreciated.

    AV

  • #2
    Are you wrapping your call by a readOnly transaction?
    Code:
        <property name="transactionAttributes">
          <props>
            <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
            ...

    Comment


    • #3
      Nope. Forgive my ignorance, but is the snipit you provided in the Spring config, or in the Hibernate config?

      Comment


      • #4
        In the Spring config:
        Code:
          <!-- Hibernate Transaction Manager -->
          <bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
            <property name="sessionFactory">
              <ref local="sessionFactory"/>
            </property>
          </bean>
        
          <!-- Hibernate DAOs -->
          <bean id="userDAO" class="org.taha.dao.hibernate.HibernateUserDAO">
            <property name="sessionFactory">
              <ref local="sessionFactory"/>
            </property>
          </bean>
        
          <!-- transactional service template -->
          <bean id="txProxyTemplate"
             class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
             abstract="true">
            <property name="transactionManager">
              <ref bean="transactionManager"/>
            </property>
            <property name="transactionAttributes">
              <props>
                <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
                <prop key="set*">PROPAGATION_REQUIRED</prop>
                <prop key="save*">PROPAGATION_REQUIRED</prop>
                <prop key="delete*">PROPAGATION_REQUIRED</prop>
              </props>
            </property>
          </bean>
        
          <!-- transactional aop-enabled services -->
          <bean id="userManager" parent="txProxyTemplate">
            <property name="proxyInterfaces">
              <value>org.taha.service.UserManager</value>
            </property>
            <property name="target">
              <bean class="org.taha.service.UserManagerImpl">
                <property name="userDAO">
                  <ref bean="userDAO"/>
                </property>
              </bean>
            </property>
          </bean>
        HTH

        Comment


        • #5
          Excellent. Thanks.

          Comment

          Working...
          X