• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dirty read is experienced for the same thread????

 
Senthil Kumar Sekar
Ranch Hand
Posts: 45
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can anyone tell me if Dirty read is experienced by the same thread only?

Because,

I have two classes and one table(Employee - 3 rows)

Class 1
1) set autocommit - false
2) selecting the emp table - prints 3 rows
3) inserting one new row
4) selecting the emp table - prints 4 rows -> Dirty Read Occurs here

Class 2
1) select the same table - It prints only 3 rows ->Does not include the new row.

So,Does that mean Dirty Read is experienced by the SAME THREAD ONLY

Thanks.

Regards
Senthil Kumar Sekar
 
Madhan Sundararajan Devaki
Ranch Hand
Posts: 312
Java MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Are these two classes, threads?
2. What type of Statement have you used?
3. What isolation levels have you set for your Statement objects?
 
Senthil Kumar Sekar
Ranch Hand
Posts: 45
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) those are two separate classes.So executing them means a separate thread.
2) Normal Statement
3) Isolation level - TRANSACTION_REPEATABLE_READ

Thanks.

Regards
Senthil Kumar Sekar
 
Madhan Sundararajan Devaki
Ranch Hand
Posts: 312
Java MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In what manner are the two classes executed? (sequential/parallel/wait-notify/....etc...)
 
Sudheer Bhat
Ranch Hand
Posts: 75
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Senthil,

I don't think your class 1 is experiencing any dirty reads. Its the regular behavior. You establish a DB session the moment you open a connection. Within the session all uncommitted changes are readable. Since you have autoCommit = false, the moment you close your connection the insert would be rolled back and any further select from class1 will/should show only 3 records on the emp table.

Your class 2 sees only 3 records since class 1 has not committed the records yet. Thus the class2 (which has a separate DB session) is not experiencing the dirty read.

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

1) those are two separate classes.So executing them means a separate thread.

Not sure what you mean by "2 classes" == "2 threads" (especially given the subject of this post). Can you explain how you instantiates these?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic