Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Transaction

 
souha jerbi
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i just want to know if we shoud open and commit the transaction for each time we want to acces the database or is it possible to execute more than a query in one transation.
and if it's the first response , how may do to prevent the case when in one service the first query is commited and the second is not (doesn't it causes in this case an integrity problem?)
thanks everybody
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Normally yes, though you don't need to use a transaction for a query.


how may do to prevent the case when in one service the first query is commited and the second is not (doesn't it causes in this case an integrity problem?)

This only a data integrity problem if the transaction isolation level is set to allow stuff that will result in data corruption (dirty reads and the like). Assuming you use read committed or higher this wont be an issue. You will suffer from lost updates unless you also implement an optimistic locking scheme, support for which comes with Hibernate.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Normally yes, though you don't need to use a transaction for a query.


Christain Bauer, a co-author of Hibernate in Action and a key player in the development of the Hibernate framework, asserts that indeed, transactions are mandatory for even database queries.

I did a training two weeks ago and all 12 people said "No" when I asked "are database transactions mandatory?". We have a long way...


I think this is a great thread, especailly where Christian gets a little impatient with his responses. Just good reading!

Christian Bauer's Opinion on the Need for Transactions with Queries - Hibernate Forum

I'd love to hear any opinions.

-Cameron McKenzie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic