Solved

spring hibernate update

Posted on 2008-10-23
3
456 Views
Last Modified: 2012-06-27
i got:
Parent and Child

when i save, i use below:
getHibernateTemplate().saveOrUpdate(parent);

so it should will auto save the child by right.

My question is, if my child data is same with database,
so will hibernate update it again?

for example:
child.setName("abc");

but the name "abc which is in db already, will it update again?
0
Comment
Question by:aaaaaa
3 Comments
 
LVL 1

Accepted Solution

by:
jV247 earned 50 total points
ID: 22857027
No, you would need a merged/managed reference to the child for that. See

http://www.hibernate.org/hib_docs/entitymanager/reference/en/html/objectstate.html

Child c = new Child();
...
saveOrUpdate(c);
c.setName("abc"); //won't automatically be saved.

However:

Child nChild = new Child();
Child mChild = merge(nChild);
mChild.setName("abc"); //triggers an update
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question