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.
|