Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default isolation level in Spring Framework

Tags:

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.

like image 817
Sekhar Avatar asked Mar 07 '12 14:03

Sekhar


People also ask

What is default isolation level?

The default isolation level is REPEATABLE READ . Other permitted values are READ COMMITTED , READ UNCOMMITTED , and SERIALIZABLE .

Which is highest isolation level in Spring transaction?

Serializable – This is the highest isolation level. A serializable execution is guaranteed to be serializable. Serializable execution is defined to be an execution of operations in which concurrently executing transactions appears to be serially executing.

What is the default isolation level in hibernate?

Default Hibernate Transaction Isolation Level For majority of databases it's Read Committed.

Is @transactional mandatory?

Propagation. REQUIRED is the default setting of a @Transactional annotation. The REQUIRED propagation can be interpreted as follows: If there is no existing physical transaction, then the Spring container will create one.


1 Answers

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) 
like image 183
beny23 Avatar answered Oct 26 '22 07:10

beny23