Reputation:
What does Spring do when I mark a transaction as read-only? What kind of improvements/drawbacks should I expect?
Upvotes: 3
Views: 681
Reputation: 6283
As per Spring documentation,
Read-only status: A read-only transaction can be used when your code reads but does not modify data. Read-only transactions can be a useful optimization in some cases, such as when you are using Hibernate.
This attribute is only a hint to the provider, the behavior depends on, in this case, Hibernate.
If you specify readOnly as true, the flush mode will be set as FlushMode.NEVER in the current Hibernate Session preventing the session from commiting the transaction.
Furthermore, setReadOnly(true) will be called on the JDBC Connection, which is also a hint to the underlying database. If your database supports it (most likely it does), this has basically the same effect as FlushMode.NEVER, but it's stronger since you cannot even flush manually.
Please refer to link for more detail.
Upvotes: 2