-->
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: Updating persistent objects
PostPosted: Thu Feb 24, 2005 12:10 am 
Senior
Senior

Joined: Tue Mar 02, 2004 6:17 pm
Posts: 151
I'm reading http://www.hibernate.org/hib_docs/v3/re ... state.html

The documentation, section 10.5 does not discuss what happens in this scenerio:

1) Object is loaded from the DB
2) The value is modified in the DB
3) Time passes
4) Does the object (in memory) pick up the changes in the underlying DB or does one need to explicitly synchronize its value somehow?

I tried reading Chapter 11 (transactions) but that didn't clear it up for me either.

Can someone please clarify and ammend Chapter 5 to discuss this?

Thank you,
Gili


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 1:20 am 
Regular
Regular

Joined: Mon Feb 23, 2004 10:42 pm
Posts: 102
Location: Washington DC
Your code needs to synchronize its value with the database

_________________
Matt Veitas


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 1:58 am 
Senior
Senior

Joined: Tue Mar 02, 2004 6:17 pm
Posts: 151
mveitas wrote:
Your code needs to synchronize its value with the database


Perhaps I wasn't clear on my question. Say I have code like this:

Cat cat = session.load(Cat.class, id);
// cat.getName() is modified in the database
String name = catgetName(); // Will this return the original name or the new name found in the database?

You said I should synchronize the object state with the database. How does one go about doing that? Are you should I should call session.load() again? Is there a way to detect whether an object state is stale or not without actually clobbering its value?

Thanks,
Gili


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 28, 2005 1:09 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Those questions are answered many times.
Basicaly it depends your tx level but
use refresh() to sync you object.
use optimistic locking to avoid any problem.
A session should not be held "too long" to avoid such problems

_________________
Emmanuel


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.