Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set query to be read uncommited?

with hibernate, how can I set a query to be read uncommitted? I don't want this to be a global setting, just want to do it on a per query basis.

like image 711
mrblah Avatar asked Jan 06 '10 20:01

mrblah


People also ask

How do you read uncommitted data?

The isolation level of the transactional support is default to READ UNCOMMITTED. You can change it to READ COMMITTED SNAPSHOT ISOLATION by turning ON the READ_COMMITTED_SNAPSHOT database option for a user database when connected to the master database.

What is read uncommitted in SQL?

READ UNCOMMITTED: A query in the current transaction can read data modified within another transaction but not yet committed. The database engine does not issue shared locks when Read Uncommitted is specified, making this the least restrictive of the isolation levels.

Should I use read uncommitted?

Read uncommitted is the weakest isolation level because it can read the data which are acquired exclusive lock to the resources by the other transactions. So, it might help to avoid locks and deadlock problems for the data reading operations.

Is read uncommitted the same as Nolock?

In a nutshell, nolock (read uncommitted) takes no shared locks to prevent other transactions from modifying data read by this transaction. It also effectively ignores exclusive locks taken by other transactions when they have added or changed data but not committed it yet.


1 Answers

Using Spring with Hibernate it is possible to have Spring controlling transactions with annotations, that is some configuration like the one below in spring applicationContext.xml:

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>

<!-- To use annotation driven in aspect mode (mode="aspectj"), it is necessary to add spring-aspects lib -->
<tx:annotation-driven transaction-manager="transactionManager" />

The best way to achieve that is to using an annotation like the one below:

@Transactional(propagation=Propagation.REQUIRED, isolation=Isolation.READ_UNCOMMITTED)
like image 168
mchamati Avatar answered Oct 04 '22 12:10

mchamati