-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Can't get Flush to work
PostPosted: Wed Mar 30, 2011 8:27 am 
Newbie

Joined: Wed Mar 16, 2011 10:54 am
Posts: 4
Been stuck on this problem a while now.
In short, When I stop the debugger before the last commit is executed am I wrong when I expect the data base to be up to date when I look in it after the flush has been called? If flush does not send all pending updates to the database then what is it for?
The database contains @New@ in the field after the last commit but not after the flush. I have 2 seperate transactions for clarity so I have the field in a known state.

Thanks .... J
Code:
Session session = HibernateUtil.beginTransaction();
      User user1 = (User)session.get(User.class, new Long("7") );   
      user1.setEmailAddress("Old");
      session.getTransaction().commit();
      
      session = HibernateUtil.beginTransaction();
      User user = (User)session.get(User.class, new Long("7") );      
      user.setEmailAddress("New");
      session.flush();
      session.getTransaction().commit();


Top
 Profile  
 
 Post subject: Re: Can't get Flush to work
PostPosted: Wed Mar 30, 2011 9:18 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I guess that depends on which transaction isolation level you are using (in the debug tool). What you are seeing indicates that you are using READ_COMMITTED. If you want to see changes that are not yet committed you should use READ_UNCOMMITTED.


Top
 Profile  
 
 Post subject: Re: Can't get Flush to work
PostPosted: Wed Mar 30, 2011 11:03 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
nordborg is right. You are probably checking your database using an SQL-Tool.
Hibernate DOES send the statements to the database when you are calling flush, but if you have a good database it does not make it visible to other transactions as long as your transaction is not committed (transactions are atomic).

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: Can't get Flush to work
PostPosted: Wed Mar 30, 2011 11:35 am 
Newbie

Joined: Wed Mar 16, 2011 10:54 am
Posts: 4
Thanks for replies :)
I'm using postgres. Tried getting the transaction level set to READ_UNCOMMITTED but can't get it working ( Task for another day ) but that explains why I don't see the changes with my sql tool until the commit.
However, here is another closely related issue i'm seeing.
Does refresh() do a dirty read from the database? I would have thought it should pull back the last persisted state of my object, and not the state that the last flush() left it in?


Code:
Session session = HibernateUtil.beginTransaction();
      User user1 = (User)session.get(User.class, new Long("7") );   
      user1.setEmailAddress("Old");
      session.getTransaction().commit();
     
      session = HibernateUtil.beginTransaction();
      User user = (User)session.get(User.class, new Long("7") );     
      user.setEmailAddress("New");
      session.flush();

      session.refresh(user);
      //User still has email set to "New",  does this mean that refresh() is doing a "Dirty" read from the database ?
      session.getTransaction().commit();


Top
 Profile  
 
 Post subject: Re: Can't get Flush to work
PostPosted: Wed Mar 30, 2011 1:48 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Quote:
I'm using postgres.


It seems like Postgres doesn't support READ_UNCOMMITTED. It will accept it but treat it as READ_COMMITTED

http://www.postgresql.org/docs/9.0/stat ... ction.html

Quote:
Does refresh() do a dirty read from the database?


Well, a transaction will always see modifications made in it's own transaction. But this is not a "dirty read" as used in the SQL terminology. Here is a nice document:

http://www.postgresql.org/docs/9.0/stat ... n-iso.html


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.