Solved

spring hibernate update

Posted on 2008-10-23
3
450 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 to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
scores100 challenge 3 84
allStar challenge 1 43
topping1 challenge 7 53
ArrayIndexOutOfBoundException 9 39
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 second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now