This is a bidirectional one-to-many association. The following map works fine when retrieving children if children exist. However, I have been unable to insert a new collection of string values on the parent since no primary key can be generated on the child table.
Here are the table schema and hibernate mapping file:
create table parent (
id number not null,
constraint parent_pk primary key (id)
);
create table child (
id number not null,
parent_id number not null,
comment varchar2(250),
constraint child_pk primary key id,
constraint child_fk foreign key references parent (id)
);
<hibernate-mapping>
<class name="parent" table="parent">
<id name="id" type="long">
<column name="id" />
</id>
<set name="children" table="child">
<key>
<column name="parent_id" />
</key>
<element column="comment" type="string" />
</set>
</class>
</hibernate-mapping>
One solution is to build a Child object and map it to the "child" table and then use <one-to-many class="Child"> tag. But that will result in an extra Java class. Are there any alternatives without creating a new Java class?
|