-->
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.  [ 3 posts ] 
Author Message
 Post subject: Automatically inserting children using implied Parent Id.
PostPosted: Tue Oct 14, 2003 7:16 pm 
Newbie

Joined: Thu Oct 02, 2003 5:39 pm
Posts: 4
Hi There,

I've searched the documentation and forum but can not find an answer to my particular question.

I have a Product object which contains a list of Software Versions (each product can contain may software versions, each software version is for just one product).

My Software Version table has an autogenerated (sequence) id field and a not null foreign key to the Product Id.

I do NOT want my SoftwareVersion object to contain a link to the Product, it contains no reference at all to the Product.
I only want my Product Object to have a list of software versions.

When I try to save the Product (with a new SoftwareVersion added to the list) it complains that it can't insert a null into the product_id field of the SoftwareVersion table.

How do I get Hibernate to use the product_id from the Product object.

The only relationship between the product and software version is in my product.hbm.xml file as follows:
...
<list name="softwareVersionList" cascade="save-update" lazy="false">
<key column="product_id"/>
<index column="product_id"/>
<one-to-many class="nz.co.vodafone.phalanx.model.SoftwareVersion"/>
</list>

Your urgent assistance with this would be much appreciated.

Thanks

Craig.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 14, 2003 8:00 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Because of the fact that Hibernate objects are not assumed to be always under the control of the container, this is only possible with -composite-elements-, not with associations.

Just make the association bi-directional.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 14, 2003 8:18 pm 
Newbie

Joined: Thu Oct 02, 2003 5:39 pm
Posts: 4
Hi Gavin,

Is it possible to make it bi-directional without explicitly having a Product object/id within the SoftwareVersion object?

If not then I guess I'll just have to add the ProductId to the SoftwareVersion object and let our designer know why I've had to change the domain model.

Cheers

Craig


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