-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate how to know which field is needed to update
PostPosted: Fri Feb 19, 2010 11:33 pm 
Newbie

Joined: Fri Feb 19, 2010 11:26 pm
Posts: 2
Hi All,

I am child on Hiberate. I read the tutorial. But, I have a question. Please see the following example:

1. Assume, there is a table, called customers.
2. The table contain a field, called age.
3. Now, I want to change the age to 10. The coding is:

tx = session.beginTransaction();
Customer customers=session.load(Customer.class, new long(1));
customer.setAge(customer.getAge()+1);
tx.commit();

I don't know, when "txt.commit()" statement is executed, Hibernate framework why know the customer's age need to update?

Thanks.

Liu Ming


Top
 Profile  
 
 Post subject: Re: Hibernate how to know which field is needed to update
PostPosted: Sat Feb 20, 2010 2:18 pm 
Beginner
Beginner

Joined: Wed Nov 21, 2007 8:02 am
Posts: 48
when hibernate retrieves an object from the database, it stores a copy( called snapshot) and gives you another copy(but still hold a refrence to it).

so when you call commit, it compares the copy it gave it to you with the copy it has(i.e with snapshot).
since you have modified the copy given to you, there will be difference between these two. So hiberanate will do an update.

This is called automated dirty checking. If you do a search for it, you will find a lot of resources.


Top
 Profile  
 
 Post subject: Re: Hibernate how to know which field is needed to update
PostPosted: Sat Feb 20, 2010 10:58 pm 
Newbie

Joined: Fri Feb 19, 2010 11:26 pm
Posts: 2
Thanks a lot.

I understand now. I will do more research.

Liu Ming


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