-->
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.  [ 4 posts ] 
Author Message
 Post subject: Session.refresh(object) Question
PostPosted: Tue Mar 20, 2007 7:41 am 
Beginner
Beginner

Joined: Wed Dec 13, 2006 10:39 am
Posts: 26
Hibernate version: 3.2.2

Name and version of the database you are using: MySQL 5

I have a problem with refreshing objects.

Code:
Station station = new Station();
station.setName("1");

SessionFactory f = KLTMContext.getSessionFactory("test_hibernate");

s1 = f.openSession();
s2 = f.openSession();
            
Transaction t = s1.beginTransaction();
s1.saveOrUpdate(station);
t.commit();      

Long objectId = new Long(station.getObjectId());

Object o = s2.load(Station.class, objectId);
   
// load object and change name to 2
o = s1.load(Station.class, objectId);
((Station) o).setName("2");
t = s1.beginTransaction();
s1.saveOrUpdate(o);
t.commit();
    
// load object and refresh, the name changes from 1 to 2
o = s2.load(Station.class, objectId);
s2.refresh(o);
   
// load object and change name to 3
o = s1.load(Station.class, objectId);
((Station) o).setName("3");
t = s1.beginTransaction();
s1.saveOrUpdate(o);
t.commit();

// load object and refresh, the name is still 2 after the refresh
o = s2.load(Station.class, objectId);
s2.refresh(o);

// load object and change name to 4      
o = s1.load(Station.class, objectId);
((Station) o).setName("4");
t = s1.beginTransaction();
s1.saveOrUpdate(o);
t.commit();
    
// load object and refresh, the name is still 2 after the refresh
o = s2.load(Station.class, objectId);
s2.refresh(o);
      
s1.close();
s2.close();


the first session.refresh() of session 2 refreshes the object right, the name of the object changes from "1" to "2", but then all session.refresh() dont refresh the name of the object to "3" or "4".
the sql statemets are always executetd but the object wont change.

So whats the behavior of session.refresh() and how do i use it the right way?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 20, 2007 7:54 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
Do you have any second level cache

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 20, 2007 8:17 am 
Beginner
Beginner

Joined: Wed Dec 13, 2006 10:39 am
Posts: 26
scesbron wrote:
Do you have any second level cache

hi,
i have not specified an second level cache in the hibernate configuration file. the cache provider class of the sessionfactory is: org.hibernate.cache.NoCacheProvider.

config:
Code:
<hibernate-configuration>
<session-factory>
<property name="hibernate.show_sql"> true </property>
<property name="hibernate.format_sql"> true </property>
<property name="hibernate.use_sql_comments"> true </property>
<property name="hibernate.cglib.use_reflection_optimizer"> false
/property>
<property name="hibernate.hbm2ddl.auto"> update </property>
<property name="log4j.logger.net.sf.hibernate">debug</property>
</session-factory>
</hibernate-configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 10:13 am 
Beginner
Beginner

Joined: Wed Dec 13, 2006 10:39 am
Posts: 26
hello again.
no one who can tell me what im doing wrong?


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