-->
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: Automatically calling update when setter called
PostPosted: Tue Nov 25, 2008 12:26 pm 
Newbie

Joined: Tue Nov 25, 2008 12:14 pm
Posts: 3
Hi,

I am running into an issue where Hibernate automatically calls update on my domain object whenever I retrieve from the database and the use a setter method to change a value. My understanding is that I should be able to set the value and then explicitly call update on the domain object in order for it to update in the dB. Please let me know what is wrong.

Thanks for your help,

anicad

Here is my code snippet:

//retrieves the appropriate record from the db based on the id
Person adult = (Person)getService().getPerson("34");

//upon setting of this ID, "update" is called to persist this to the db. //Why?
adult.setFamId(new Long("887"));


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2008 3:30 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
One of main features of Hibernate is automatic dirty checking, which means that Hibernate will automatically detect changes you make to your objects and update the database when the transaction is committed.

If you don't want this to happen you need to evict the object in question from the Hibernate session by calling Session.evict().


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2008 4:10 pm 
Newbie

Joined: Tue Nov 25, 2008 12:14 pm
Posts: 3
Thanks for the information, Nordborg. Is there a way to disable automatic dirty checking for all objects? Where is this property being set?

Thanks for your help,

anicad


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2008 6:38 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Quote:
Is there a way to disable automatic dirty checking for all objects?


Not that I know of. After all, this is one of the main Hibernate features. I think it has to be done programmatically one way or the other.

The Session.update() method should only be used for objects that are previously not associated with the session (for example, has been evicted with Session.evict()).


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.