-->
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: Foreign keys in composite primary keys issue
PostPosted: Fri Jun 17, 2011 7:02 pm 
Newbie

Joined: Fri Jun 17, 2011 5:49 pm
Posts: 1
I have the following mappings like the ones found in page 364 of Java Persistence With Hibernate and page 336 of Hibernate in Action

<class name="Title" table="TITLE">
<composite-id name="titleId" class="TitleId">
<key-property name="title" column="TITLE_ID"/>
<key-many-to-one name="person" class="Person" column="PERSON_ID"/>
</composite-id>
...
</class>

<class name="Person" table="People">

<set name="titles" inverse="true" cascade="save-update">
<key column="PERSON_ID"/>
<one-to-many class="Title"/>
</set>
</class>

- I create the Title object when I create the Person object
- This is why I have used the key-many-to-one option in the composite key mapping of Title
- The other option in the books assume the Person object has already been persisted to the database, so the id is available when creating the TitleId object
- My use-case is to create these two objects with one operation (one save operation on Person)

is it possible to achieve a save on Person that cascades to Title without using key-many-to-one for a composite key?

Thanks,
Wale.


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.