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

ONE Transaction two queries

 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when I do something like this and have the container manage my Transactions:



Does the two queries works within ONE Transaction (something like PreparedStatement)?

Imaging I have values in query 1 with reflects to the values in query 2.
Now the values of query 1 does change in the database, but query 1 has already returned the (old) values.
Does the query 2 take the values from query 1 (which was already done) and ignore the new values in the database?

 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Does the query 2 take the values from query 1 (which was already done) and ignore the new values in the database?

Depending on your transaction isolation level, yes - though strictly it still gets the vaules from the database the database just doesn't let you see the uncommitted changes. The one time this would not be the case is if in the same transaction you also update your values in which case you would be able to see those updates (though no one else would).
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay, so no dirty reads can occur with the default transaction-level as the two queries are passed in one transaction.

thanks
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends what your default transaction level is but yes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic