-->
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.  [ 6 posts ] 
Author Message
 Post subject: Update of collection instead of save.
PostPosted: Fri Sep 10, 2004 6:21 am 
Beginner
Beginner

Joined: Tue Jan 27, 2004 8:25 am
Posts: 45
Hi!
I'm trying to save a new persistent object, wich contains a map of children objects. So I create te parent object, I assign the children to it's map, and when I save the parent object, I get an exception:

Code:

Hibernate: insert into AllotmentChart (contract) values (?)
Hibernate: update AllotmentChartData set chartData=? where contract=? and chart=? and year=?
31   [main] ERROR net.sf.hibernate.impl.SessionImpl  - Could not synchronize database state with session
net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)



... It is saving ok the parent object (AllotmentChart )... but it is trying to update the children objects (AllotmentChart Data).
So I was wondering why it


Top
 Profile  
 
 Post subject: Re: Update of collection instead of save.
PostPosted: Fri Sep 10, 2004 6:36 am 
Newbie

Joined: Fri Jul 16, 2004 2:02 am
Posts: 13
I think,
You are not setting the objects of child table back to parent one.
i.e For each object of AllotmentChartData,
you need to call a method in Allotment chart to set the object of
AllotmentChart!

_________________
Kary


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 10, 2004 6:49 am 
Beginner
Beginner

Joined: Tue Jan 27, 2004 8:25 am
Posts: 45
What I, basically, do is:

Code:

AllotmentChart chart = new AllotmentChart();

AllotmentChartData chartData1 = new AllotmentChartData();
chartData1.stChart(chart);
chartData1.setChartData(.....);

HibernateSession.currentSession().save(chart);
HibernateSession.currentSession().flush();

// And it inserts the nev chart, but tries to update chartData1...



Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 10, 2004 7:03 am 
Beginner
Beginner

Joined: Tue Jan 27, 2004 8:25 am
Posts: 45
It seems as if Hibernate thinks the children exists and tries to update them instead of inserting them as new persistent objects....
Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 10, 2004 7:11 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This is covered in the doco and FAQ and many forum threads.

If you want cascade="save-update" to work with a composite-id class, you must use Interceptor.isunsaved() to distinguish new from detached instances.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 10, 2004 7:17 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Or add a <version> or <timestamp> property.

http://www.hibernate.org/hib_docs/refer ... d-cascades


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