-->
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.  [ 1 post ] 
Author Message
 Post subject: Automatically save child object when parent saved
PostPosted: Mon Nov 22, 2004 11:01 am 
Regular
Regular

Joined: Sun Nov 07, 2004 3:39 pm
Posts: 77
I've been beating my head against a wall with this one and I was hoping someone might be able to help.

I have a number of classes I wish to persist, each of which implements an AddressOwner interface and contains a collection of Address objects, which I'm mapping as one-to-many relationships, using an 'address' table. Because the same class (Address) is used with a number of different 'parent' or 'one' classes, I can't specify the 'one' class in my many-to-one tag for the Address class. I did not think this would matter unduly as I am able to call setAddressOwnerId in the addAdress method all my 'one' classes implement.

This works nicely in the case of previously stored 'one' (AddressOwner) records which have had their ids assigned, but not in the case of new records, where the parent id, which is still null, gets assigned to the child Address.

I understand that if I specify the many-to-one class for the child in the mapping file, then Hibernate first inserts the parent and then the child, using the new parent id. Given that I am not able to specify the many-to-one class, for reasons given above, is there any other way in which I can have Hibernate automatically save the child with the appropriate id when the parent is saved?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.