How to read my own uncommitted data but not others'
Anne Forumer
Ranch Hand
Joined: Apr 19, 2004
Posts: 70
posted
0
While using a transaction, it seems that after I read data, say A, from database, make changes to it to change it to B, update the database and then I read the database again, before committing, I get the original data, A.
Is there a way for me to get the changed data, B, without getting dirty data from other transactions?
I am doing this in EJB3.0
Thanks in advance.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 32765
posted
0
I'm a bit rusty on this, but check the get/setTransactionIsolation methods of the java.sql.Connection class. One of the levels should provide this. I'm not sure how to tell EJB to use a particular level, though, but I seem to remember that it is possible (provided the underlying DB supports that particular level).
If I use isolation level of uncommitted read, I could read data in another transaction, which I don't want. Also, I want to read this data before I commit, so I wouldn't want "committed read" either. Am I asking for something impossible?
To reiterate, I'd like to read my own updated data, not yet committed.
Anne, I'm moving this to the JPA (EJB 3.0) forum. EJB 3.0 caches data and only commits at the end of the transaction or when you specify to flush. This means the effects involve more than just the transactions of JDBC.