-->
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: New user with Caching problem
PostPosted: Fri May 30, 2008 10:58 am 
Newbie

Joined: Mon Oct 01, 2007 9:14 am
Posts: 6
Location: Virginia
I have just started using Hibernate (with Netbeans 6.1). Almost everything seems to be working properly.. I'm writing a small web application which uses a MySQL database.

I have a class 'User' which I am attempting to update. I make the changes to the User object, call session.save(u) and tx.commit() and I can see the changes in the database. So far, so good.

Now I log out of the web app and log back in as the user I just modified. And the field that got changed (an access control field named 'Role') shows the original value, not the changed value. If I kill Tomcat and restart it, then when I log in the new user Role value shows up.

Somehow, the original user information is being cached, and I don't see where that happens. Can someone point me in the right direction? When I logged in the second time, I reloaded the user from the database (I think) but that didn't seem to help.

Thanks very much,

nbc


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 31, 2008 8:02 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
if you use Hibernate to update your user and login and update happens in the same webapplication with the same sessionfactory and you haven't changed anything of the cache behaviour than it is probably you caching the user somewhere.

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject: Cache problem
PostPosted: Tue Jun 03, 2008 11:41 am 
Newbie

Joined: Mon Oct 01, 2007 9:14 am
Posts: 6
Location: Virginia
I have not changed the cache behavior. I use the following routine to read my user info from the database:

public void updateDpUser() {
List<User> listUser = null;
try {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
Transaction tx = session.beginTransaction();
Query q = session.createQuery("from User");
listUser = (List<User>) q.list();
} catch (Exception e) {
Logger.error("Failed to load users: Exception " + e);
}
dpUser = new User[listUser.size()];
int i = 0;
Logger.info("UPDATE DPUSER: There are " + dpUser.length + " users");
for (User u : listUser) {
dpUser[i++] = u;
u.dump();
}
}

This loads the user data and I can display it in a table. When I edit a user, I do the following to update it:

if (sb1.getBCreateUser() == true) {
editUser.setUserId((String) txt_UserId.getText());
hibernateSession.save(editUser);
} else {
hibernateSession.saveOrUpdate(editUser);
}
hibernateTx.commit();
sb1.updateDpUser(); // **** RELOAD THE DATA ARRAY FOR THE TABLE

The 'dump' call shows the ORIGINAL (unmodified) data. But a 'select * from users' in a mysql xterm window shows that the table has been modified. So when I call the updateDpUser it is picking up a cached version somewhere - and it isn't mine since I create a new array in updateDpUser... So can you tell me what I'm doing wrong?

Note that the failure is intermittent - sometimes the table will come back with the correct (updated) information and sometimes it won't. The fact that the 'dump' fails to reflect the change indicates to me that Hibernate has cached something...

Can you tell me how to clear the cache?? I tried adding a line that says

hibernateSession.setCacheMode(CacheMode.IGNORE) but that did not work.

thanks

nbc


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 04, 2008 10:18 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
I tend to agree that the application must be caching the object somewhere. Do a refresh call in your code, and set a breakpoint in it and inspect the value of the object coming back from Hibernate. Perhaps you are shadowing a variable somewhere?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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.