Announcement Announcement Module
Collapse
No announcement yet.
Isolation/Locking help required Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Isolation/Locking help required

    Hi,

    We have a "job" that is split into multiple chunks, each on a different thread, each of which does some work and then updates some Hibernate objects (which are then saved).

    I'm trying to figure the transaction attributes for the method, but can't seem to isolate the threads so that they only one can have access and update the objects at a time - currently 2 threads sometimes get access to them at the same time, stomp on each other, and lead to ugly exceptions.

    I have tried setting the isolation level to ISOLATION_SERIALIZABLE, which I understand is the highest, but it doesn't seem to help.

    Can anyone point me in the right direction please?

    My applicationContext snippet follows (the method that gets called is PrinterGroupDAO.updateGroups(...)).

    cheers,

    David


    <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA). -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
    <property name="sessionFactory">
    <ref local="sessionFactory" />
    </property>
    <!-- inject directly with data source to allow the same TM to work with JDBC -->
    <property name="dataSource"><ref local="dataSource"/></property>
    </bean>

    <!-- Transaction Interceptor -->
    <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor .TransactionInterceptor">
    <property name="transactionManager">
    <ref bean="transactionManager"/>
    </property>
    <property name="transactionAttributeSource">
    <value>
    com...ServiceInfoDAO.archive*=PROPAGATION_REQUIRED
    com...ServiceInfoDAO.update*=PROPAGATION_REQUIRED
    com...ServerInfoDAO.delete*=PROPAGATION_REQUIRED
    com...PrinterGroupDAO.update*=PROPAGATION_REQUIRED ,ISOLATION_SERIALIZABLE
    </value>
    </property>
    </bean>

  • #2
    Does each thread have its own transaction, or are they sharing a single transaction?

    Comment


    • #3
      The threads get spawned off via a Message Queue. I didn't know they could share a transaction (though I'm relatively new to all this), so I believe they have they own Hibernate Session and own Transaction.

      Could you explain a little further if that doesn't make sense?

      cheers,

      David

      Comment


      • #4
        I have created a test case to replicate this - I create 2 threads which call the same method, that's supposed to be using ISOLATION_SERIALIZABLE.

        I seeing 2 transactions and Hibernate Sessions being created, but I'm not seeing any isolation and the changes stomp on each other.

        Any ideas please?

        cheers,

        David

        Comment


        • #5
          Ok - found the problem!!

          We're using Firebird, which has it's own non-standard Isolation levels (why?!!!).

          It has one which is roughly equivalent, but anyone know how to set a non-standard isolation level through Spring/Hibernate?

          cheers,

          David

          Comment

          Working...
          X