Oracle Deadlock when a Hibernate application loads read-only data

We encounter an Oracle Deadlock error (org.hibernate.util.JDBCExceptionReporter - ORA-00060: deadlock detected when waiting for a resource). It has been suggested that the problem is with a process that performs read-only operations using Hibernate, while another process is updating on the same line.

The readonly process is configured using Hibernate and Spring. We did not explicitly define a transaction for the service. Although this may not be ideal - I do not understand why Hibernate will try to get an exclusive lock on the line if save / update operations were not performed - only get / load.

So my question is: Hibernate, when there is no explicit transaction management, try to get a read / write lock on the line, even if only the "loading" of the object is done. No save / update.

Is it possible that defining a transaction around a service that loads data, and then, in particular, READONLY on transactionAttributes attributes, will cause Hibernate to ignore an existing row lock and just load the data for readonly purposes?

Here are some sample code:

We use the HibernateDaoTemplate to load the record.

public class HibernatePurchaseOrderDataService extends HibernateDaoSupport implements PurchaseOrderDataService {
    public PurchaseOrderData retrieveById(Long id) {
        return (PurchaseOrderData)getHibernateTemplate().get(PurchaseOrderData.class, id);
    }
}

Spring configuration for the service calling this method:

<bean id="orderDataService"
      class="com.example.orderdata.HibernatePurchaseOrderDataService">
    <property name="sessionFactory" ref="orderDataSessionFactory"/>
</bean>

<bean id="orderDataSessionFactory"
      class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="hibernateDataSource"/>
    <property name="hibernateProperties" ref="hibernateProperties"/>
    <property name="mappingResources">
        <list>
            <value>com/example/orderdata/PurchaseOrderData.hbm.xml</value>
            <value>com/example/orderdata/PurchaseOrderItem.hbm.xml</value>
        </list>
    </property>
</bean>

The actual deadlock occurs on one of the PurchaseOrderItem records loaded by the PurchaseOrder download call.

, ? - , ​​ , ?

<bean id="txWrappedOrderDataService"
      class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager" ref="transactionManager"/>
    <property name="target" ref="orderDataService"/>
    <property name="transactionAttributes">
    <props>
        <!-- all methods require a transaction -->
        <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
    </property>
</bean>

. DataBase , , , , " " . "UPDATE", , . , Hibernate ( ). , , .

- FLUSH - ? , readOnly ...

+5
6

, , readOnly.

, ( ) - . - Hibernate , .

readOnly !

<bean id="txWrappedOrderDataService"
  class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"/>
<property name="target" ref="orderDataService"/>
<property name="transactionAttributes">
    <props>
        <!-- all methods require a transaction -->
        <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
</property>

+1

, , , . setter String, null "". . , . , , hibernate .

+2

- ? , Hibernate, - , ? , , , , ( , SELECT)...

0

.

, , , Date() - - , , ,

0

log4j.logger.org.hibernate.persister.entity.AbstractEntityPersister = TRACE

log4j. , , . , "", null, . , .

0

, . , , - , .

0

All Articles