I'm stuck on a one-to-many association and how the ID gets assigned on the many end.
With existing data I can load an A and all its Bs get loaded for me in the map just fine. I can even modify elements of B, save A and have those changes to B written correctly.
The problem is when I create a new A with a new set of Bs. Hiberrnate generates a new ID and writes the A correctly. It then tries to write every column of the new Bs except for their a_id column. How does the generated ID for A get propagated to its Bs?
Hibernate version:
3.0.5
Schema:
Code:
create table a
(
a_id integer not null,
primary key (a_id)
);
create table b
(
a_id integer not null,
code integer not null,
desc varchar(255),
primary key (a_id, code),
foreign key (a_id) references a (a_id)
);
Mapping documents:Mapping for A:
Code:
<class name="A" table="a">
<id name="id" column="a_id" type="string" unsaved-value="null">
<generator class="my.uuid.Generator"/>
</id>
<map name="foo" table="b" lazy="false" cascade="all">
<key column="a_id"/>
<map-key column="code" type="string"/>
<one-to-many class="B"/>
</map>
</class>
Mapping for B:
Code:
<class name="B" table="b">
<composite-id name="aId" column="a_id" type="string"/>
<composite-id name="code" column="code" type="string"/>
<property name="desc" column="desc"/>
</class>