-->
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.  [ 6 posts ] 
Author Message
 Post subject: Session refresh method
PostPosted: Thu May 13, 2004 11:16 am 
Newbie

Joined: Thu Jan 08, 2004 12:05 pm
Posts: 14
Hi!

Session.refresh method javadoc says:
Quote:
Re-read the state of the given instance from the underlying database.
.
However if I load an object in one Session and then try to refresh it in other Session where an object with the same PK was previous loaded, its state remain the same.

Code:

        Object pp1 = session1.load(..); //use same pk

        session1.close();

        Object pp2 = session2.load(..); //use same pk
        session2.refresh(pp1);

        ///here object pp1 have the same state as the one loaded by session1


        session1.close();



This is the corect behaviour or I do something wrong ? If I comment the line that loaded the other object in session2 all works just fine.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 13, 2004 11:19 am 
Newbie

Joined: Thu Jan 08, 2004 12:05 pm
Posts: 14
I forgot to tell that I'm using hibernate 2.1.3


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 13, 2004 11:23 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
i just don't see why you're doing this, what do you to do.

refresh() is usefull when you think your object is not up to date that is to say it has been modified out (example trigger)
Code:
        Object pp1 = session1.load(..); //use same pk
        pp1.setXXX(value);
        session1.commit();
        //here a trigger onUpdate is executed
        session1.refresh(pp1);
        //your object is now uptodate
        session1.close();


but there are many other use case where refresh can be usefull


Anthony


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 13, 2004 11:41 am 
Newbie

Joined: Thu Jan 08, 2004 12:05 pm
Posts: 14
I have a scenario for a web applicatio were two users modify the same data and I have to refresh object state to make some checkin before comit some data.

I'll try to be a little more explicit:
Code:

   //user1
   Object obj1 = session1.load(.., pk);

   
   //user2
   Object obj2 = session2.load(.., pk); //obj1 is the same persistent object  as obj2
   obj2.setXXX();
   session2.update(obj2);
   session2.commit();

   //user1
   Object obj3 = session3.load(.., pk); //ob3 is the same as obj2, obj1
   session3.refresh(obj1);
   
   //some logic here



When I refresh obj1 using session3 I still don't see the changes comited with session2


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 13, 2004 12:18 pm 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
Try the following code with the second session:

Code:
session.lock(yourObject, LockMode.NONE); // bind your object to the new session;
session.referesh(yourObject); // referesh


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 14, 2004 3:22 am 
Newbie

Joined: Thu Jan 08, 2004 12:05 pm
Posts: 14
I resolved the problem using other session.

thanks for your help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.