Hibernate version: 3.1
I have a class Foo, and I have another class Bar whose composite id is Foo.id and a type. The Foo class holds a Set of Bars. I've implemented an Interceptor so that hibernate will know when Bar isTransient. The documention suggests to me that if i create a Foo, and add some Bars to it, when I attempt to persist Foo, the Bar objects will be persisted because i've implemented isTransient correctly, it knows to use Foo.id when inserting the Bar objects into the db. However, that does not appear to be the case. The bar insert errors out because the id is null and of course part of the composite pkey on bar can't be null. Any thoughts? It seems like i could get past this if i had a reference to Foo in Bar, however that seems like a hack as I have no need for a bidirectional relationship between those classes.
Here are the relevant mapping docs.
<class name="FooParent" table="foo_parent">
...
<joined-subclass name="Foo" table="foo">
<key column="foo_id"/>
...
<set name="bars" cascade="save-update">
<key column="foo_id"/>
<one-to-many class="Bar"/>
</set>
</joined-subclass>
</class>
<class name="Bar" table="bar" discriminator-value="0">
<composite-id name="id" class="Bar$Identifier">
<key-property name="id" type="long" column="foo_id"/>
<key-property name="typeId" type="integer" column="type_id"/>
</composite-id>
<discriminator column="type_id" type="integer" insert="false"/>
<property name="col1"/>
<subclass name="Bar1" discriminator-value="1"/>
<subclass name="Bar2" discriminator-value="2"/>
</class>
Thanks
|