-->
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.  [ 11 posts ] 
Author Message
 Post subject: Updating persistent Object which contains an updated Collect
PostPosted: Thu Jan 27, 2005 9:19 am 
Regular
Regular

Joined: Thu Jan 27, 2005 8:58 am
Posts: 80
Hello,
I#ve got following problem:
1. I'm loading an persistent object from my MySQL Database. This object contains a set of other objects. (These objects are found by a many-to-many association to another table)
2. During my application I add some more objects to this set.

So far so good

3. Now I want to update the main-object in that way, that the new objects in the set are added to the table, which refers to the n-m-relationship.

Is this possible? For learning hibernate I've used 'A Developer's Botebook' by James Elliot, but there's only a example for saving a new Object, containing a set.


This is the code for the set from the main-object mapping-file:
<set name="feiertage" table="standort_feiertage" inverse="true" >
<key column="stand_id" />
<many-to-many class="de.company.controlling.hibernate.Feiertag" column="f_id" />
</set>

Thanks
FPC


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 27, 2005 9:22 am 
Newbie

Joined: Wed Jan 26, 2005 11:01 am
Posts: 18
set cascade property in mapping to save-update or all(-delete-orphan)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 27, 2005 9:23 am 
Newbie

Joined: Wed Jan 26, 2005 11:01 am
Posts: 18
that is: set the cascade property on the many-to-many to save-update, since all infers delete and this is probably not what you want on a many-to-many.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 27, 2005 9:31 am 
Regular
Regular

Joined: Thu Jan 27, 2005 8:58 am
Posts: 80
mwinkels wrote:
set cascade property in mapping to save-update or all(-delete-orphan)


That means, if I alter my code to this:

<set name="feiertage" table="standort_feiertage" inverse="true" cascade="save-update" >
<key column="stand_id" />
<many-to-many class="de.company.controlling.hibernate.Feiertag" column="f_id" />
</set>


Hibernate will put the IDs of the Feiertag- and the Standort-object into the standort_feiertag-table? That's what I'm aming for.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 27, 2005 9:36 am 
Newbie

Joined: Wed Jan 26, 2005 11:01 am
Posts: 18
That it will do if you update the "main object". If you set the cascade property, the newly created "Feiertage"s will be inserted in theit own table as well.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 27, 2005 9:41 am 
Regular
Regular

Joined: Thu Jan 27, 2005 8:58 am
Posts: 80
Ok, but I've already tried to update the main-object and hibernate does not throws any exception, but there are no new entries in my 'standort_feiertage'-table...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 27, 2005 9:45 am 
Newbie

Joined: Wed Jan 26, 2005 11:01 am
Posts: 18
Normally it should complain if a reffernced collection contains transient objects and the association is not cascading. Maybe you can show the code.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 27, 2005 9:46 am 
Regular
Regular

Joined: Thu Jan 27, 2005 8:58 am
Posts: 80
I've got the problem!!!

<set name="feiertage" table="standort_feiertage" inverse="true">

didn't work, but

<set name="feiertage" table="standort_feiertage">

work fine!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 27, 2005 9:50 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
it's really usefull to read the reference guide and the wiki about parent/child relationship.
Have you read it?

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 27, 2005 9:54 am 
Regular
Regular

Joined: Thu Jan 27, 2005 8:58 am
Posts: 80
I've read the Chapter in 'A Developer's Notebook', but I've looked at the wrong example for copying it. The example showed the other side of the n-m-realtionship...

Sry


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 27, 2005 9:58 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
you'll have to check twice some 'A Developer's Notebook' samples... all is not correct in this book.
It's ok to learn some ideas but check the wiki and reference guide, it has good explanations.
Hibernate in action is actually the best book to understand what is behind all mapping parameters.

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


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