Solved

spring hibernate update

Posted on 2008-10-23
3
458 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
topping1 challenge 7 133
Core Java. What output will be and why ? 6 68
maven project error 5 77
diffSum example 4 57
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
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…
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.

740 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