Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is read only transaction and how it helps me

 
srini carry
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
read-only transation , why should I use this , how this transaction attribute can help me ? please explain me advantages of using read-only attribute for a transaction, I donto know If I should I use this or not
 
Eduardo Bueno
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Spring documentation states:
Read-only status: a read-only transaction does not modify any data. Read-only transactions can be a useful optimization in some cases (such as when using Hibernate).
 
srini carry
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eduardo Bueno wrote:As Spring documentation states:
Read-only status: a read-only transaction does not modify any data. Read-only transactions can be a useful optimization in some cases (such as when using Hibernate).


why is it useful with hibernate , how can I decide whether to use it or not ?
 
Eduardo Bueno
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use it in transactions where you are simply fetching data, i.e. SELECT statements. I don't know what the documentation means when referring to Hibernate.
 
Andy Hahn
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes as previous posters suggest, use when fetching data. If using hibernate, by using this you can avoid having to lazy load things since it keeps the session open until the need of the transaction. The alternative is to set lazy="false" in hibernate which can lead to lots of worse things such as loading huge object graphs when not needed.
 
Andy Hahn
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

open until the need of the transaction


should be "open until the end of the transaction"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic