Carlos Jaime C. De Leon
Carlos Jaime C. De Leon

Reputation: 2896

JPA transaction combination of readonly and read uncommitted

Using Spring transactions, JPA with Hibernate implementation.

I have marked a method as:

@Transactional(readOnly=true, isolation=Isolation.READ_UNCOMMITTED)

Does this combination of readOnly and read uncommitted valid? I am using this on a method who's native sql is a select statement for a report page. First, I am marking it as read uncommitted so that it does not get stuck waiting on the table which gets frequently updated, as user wants to generate report even during processing time (a warning is shown if this happens). Second, I am marking as readonly to tell JPA not to keep the entities in the persistent context.

Is this a correct understanding?

Upvotes: 1

Views: 5069

Answers (1)

Anand Kulkarni
Anand Kulkarni

Reputation: 1201

Since you need intermediate data during the processing time, READ_UNCOMMITTED isolation level makes sense. ReadOnly transaction will make sure that all the sql statements in that particular transaction are Select statements and if it finds any Insert/Update sql statements, it will immediately throw an error. I think ReadOnly is just an additional check to make sure that your are not updating any data during a particular transaction.

Upvotes: 3

Related Questions