Default isolation level in Spring Framework

Sekhar picture Sekhar · Mar 7, 2012 · Viewed 21k times · Source

I have a method in service layer which does the update functionality to database.

@Transactional(propagation = Propagation.REQUIRES_NEW)
public void update(final Object obj){
    // some code here
}

Now I want to know what is the isolation level for this method set by Spring framework?

I am a newbie to Spring, just wanted to make myself comfortable with transactions.

Please share some best practice and ways to set isolation level to avoid deadlocks and thus preventing same user trying to update his record from different browsers.

Answer

beny23 picture beny23 · Mar 7, 2012

According to the docs (Isolation.DEFAULT), it uses

Use the default isolation level of the underlying datastore.

As you are using the @Transactional annotation, I would set the isolation level there, e.g.:

@Transactional(propagation=Propagation.REQUIRES_NEW, isolation=Isolation.SERIALIZABLE)