-->
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: Objects not refreshed when outside app changes the database
PostPosted: Wed Dec 15, 2004 3:59 pm 
Newbie

Joined: Wed Dec 15, 2004 3:49 pm
Posts: 2
Hibernate version: 2.1

I'm a newbie to Hibernate, and can't find help on why my User object doesn't reflect changes made in the database between calls. For example:

1) session.load User object. Let's say the name is "Ving"
2) Display User object on jsp. Displays "Ving".
3) Change the user's name in the database manually to "Bing".
4) session.load User object.
5) Display User object on jsp. Still displays "Ving", rather than "Bing".

My load code basically looks like:

Session session = HibernateFactory.currentSession();
User user = (User) session.load(User.class, new Integer(id));
HibernateFactory.closeSession();

I have tried a number of variations on session.refresh(), session.flush(), etc., but nothing seems to work.

Any ideas on what the problem is?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 15, 2004 5:25 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you are using a completely new session ?
how about the connection ? have you started a new transaction so you will see new changes ?

Have you by accident enabled second level cache on the class ?

in other words - if you use a fresh new session and connection and doesn't have any 2nd level cache I promise you that hibernate will be reading the latest values from the database...

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Solved
PostPosted: Fri Dec 17, 2004 12:40 am 
Newbie

Joined: Wed Dec 15, 2004 3:49 pm
Posts: 2
Your suggestion to use transactions was the key. I assumed that if all I was doing was retrieving data (i.e. SELECT but not INSERT, UPDATE, or DELETE), then I would not need transactions... Guess I was wrong.

Thanks for the help.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 17, 2004 3:13 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
transactions also influence READ only stuff (standard database behavior)

if using transactions solved your problem, i would also say you should check your session and connection usage....it looks like you are only using the same connection or session for all your persistence - maybe that is not really what you want ?

_________________
Max
Don't forget to rate


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.