0

This is a simple question may be

in my code i am doing a

user = em.find(User,pk);
user.setName("name");
em.flush();

after this flush() statemenet using debugger i stop using a breakpoint. I now check using my sql developer tool to see if the changes have been made in DB. I dont see the changes completed in DB.

What does this mean about flush command.

  1. The sql generated by the flush will be send to DB but then on the db it is queued up waiting for a commit statement to come through ? and the sql statements are not applied yet ?

Modification 1: So may be i was not clear the first time as to what i am trying to do

I have a clustered setup where on Node 1: in Transaction 1 one i am changing some parameters , say name of User entity and doing a flush() on them so thy get to DB. I cannot do a commit yet as there are lot other operations which needs to happen in transaction

Parallel to this On Node(Machine) 2 in Transaction 1 i am getting the user entity. Now in this transaction the only desire is to check the latest name on the user. This is what happens parallely and what i need to do . Can someone let me know how to do this so that distributed nodes see the latest changes.

Node 1                                       Node 2 
try{                                      try {
    em.getTransaction.begin                 em.getTransaction.begin
    user = em.find(User,pk);
    System.out.println.(user.getName())
    /* this prints JERRY*/
    user.setName("TOM");
    em.flush();
    ...
    ...                                     user = em.find(User,pk);
                                            System.out.println.(user.getName()) 
                                            /*This should print TOM*/

    ...
    em.commit()                             //no commit in this transaction  
 }  catch (Exception e) {                    } finally {


   //rollback                                 }
} finally {

}
user804979
  • 913
  • 1
  • 6
  • 9
  • 1
    read about transaction isolation levels – DataNucleus Jul 09 '12 at 06:31
  • You would want to use Read Uncommitted (http://stackoverflow.com/questions/2471055/why-use-a-read-uncommitted-isolation-level) but I have to recommend that you DON'T want to do this. I would highly recommend you figure out some alternative way of organizing your code so that you can partially commit individual units of work without a long running blocking transaction. Read uncommitted can be an ugly track to go down unless you are prepared for the ramifications. – jjathman Jul 10 '12 at 02:09

2 Answers2

0

You are likely correct that your transaction hasn't been comitted yet so the changes are not visible outside of the transaction that persisted them. What are you using to start and stop your transactions?

jjathman
  • 12,536
  • 8
  • 29
  • 33
0

flush() does not commit the transaction, only writes to the database. To see the changes in another session you need to commit the transaction.

James
  • 17,965
  • 11
  • 91
  • 146