-->
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.  [ 12 posts ] 
Author Message
 Post subject: very very strange and interesting problem! pls help!
PostPosted: Wed Dec 21, 2005 1:26 am 
Newbie

Joined: Thu Dec 01, 2005 3:43 am
Posts: 11
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:2.1

Hello

i have very interesting problem.

my web application is running and client is using the aplication and everything goes fine. client can edit any data on the page and view the modifed data and so on. so no problem.
but
when i modify some data from console of mysql(REMEMBER: DIRECTLY USING MYSQL), then when the client refresh the page he is seeing old data!

but when i restart tomcat then my application works successfully.

pls tell me the reason behind that.

Thank You

Chinmoy


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 21, 2005 2:47 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Cache ?????


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 23, 2005 6:03 am 
Newbie

Joined: Thu Dec 01, 2005 3:43 am
Posts: 11
sorry i cant understadnd what u said.
pls write in details.

Thank You

Chinmoy


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 23, 2005 6:17 am 
Beginner
Beginner

Joined: Thu Sep 01, 2005 7:43 am
Posts: 31
Location: León (Spain)
If you make some changes using direct SQL, you need to use session.refresh() on the objects you have loaded. Hibernate uses an object cache and you are making changes without notifying it to Hibernate.

Bye.

_________________
Please rate...

Expert on Hibernate errors... I've had them all... :P


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 23, 2005 6:25 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi,

The value will not be there in 1st level cache. So what you need to do is to refresh the session which will refresh the Cache too.

session.refresh(obj);

Is that Clear now?

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 25, 2005 11:11 am 
Newbie

Joined: Thu Dec 01, 2005 3:43 am
Posts: 11
hello

thanks for ur reply. and things now clear to me.
so it is not possible to see changed data without restarting the tomcat.
am i write?

Thank you

Chinmoy


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 25, 2005 11:45 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
go learn about proper usage of sessions.

You should not just use a single one forever.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 25, 2005 11:54 pm 
Newbie

Joined: Thu Dec 01, 2005 3:43 am
Posts: 11
i am using eclipse plugin for hibernate(hibernate syncronizer) that autometiically generates
DAO classes and others. it can give u session with getSession() method and can close seesion using closeSession() method.

so when i used this method i always uses session for any busness operation and closes it when it finishes.

just like the following code:

###############################
session = getSession();



Company company=(Company)session.load(Company.class,companyOid);





divisions=company.getDivisions();



tempDivisions=new ArrayList();





for (Iterator i = divisions.iterator(); i.hasNext();) {

Division division = (Division) i.next();



tempDivisions.add(division);





}



closeSession();
#########################################
what more i can do?

chinmoy


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 26, 2005 4:28 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
If you also properly begin and commit your transaction you should not read old data.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 26, 2005 10:04 am 
Regular
Regular

Joined: Wed Dec 21, 2005 6:57 pm
Posts: 70
No need to restart Tomcat. Tomcat has it's own caches for web processing, but people in this thread are talking about Hibernate's data cache.

Hibernate keeps the data for the objects in an array-based format (or something like that), and then rebuilds objects from this in-memory data cache. If the database changes, this in-memory representation of the data will not be updated unless you configure Hibernate to refresh the cache. You can programmatically configure this and no need to restart Hibernate.

Look for articles on using Hibernate with a shared database -- by writing directly to the DB you are simulating a situation where other processes are using the same DB as Hibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 26, 2005 1:05 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
that is only relevant when using 2nd level cache.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 26, 2005 11:17 pm 
Newbie

Joined: Thu Dec 01, 2005 3:43 am
Posts: 11
How can i programmatically configure to refresh the cache?
is there any ariticle or any example?

Chinmoy


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