What is considered the best way to generate part of a composite key in a parent/child relationship?
tariff is the parent and has an id column, tariff_accessorial is the child and has a composite key of seq and tariff_id. Ideally, I'd like to be able to specify the sequence name for the child seq part of the key.
I read
this in the wiki, but I don't think that's exactly what I'm looking for.
Current mappings (using
http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd):
Parent table:
Code:
<hibernate-mapping>
<class
name="com.*****.cc.objectlib.tariff.TariffState"
schema="eousr"
table="TARIFF">
<id name="id" type="java.lang.Long">
<column name="TARIFF_ID"/>
<generator class="sequence">
<param name="sequence">tariff_seq</param>
</generator>
</id>
<!-- properties deleted for brevity -->
<!-- associations -->
<!-- bi-directional one-to-many association to TariffAccessorialState -->
<set
name="tariffAccessorialStates"
lazy="true"
inverse="true">
<key>
<column name="TARIFF_ID"/>
</key>
<one-to-many
class="com.*****.cc.objectlib.tariff.TariffAccessorialState"/>
</set>
<!-- other associations deleted for brevity -->
</class>
</hibernate-mapping>
Child table:
Code:
<hibernate-mapping>
<class
name="com.*****.cc.objectlib.tariff.TariffAccessorialState"
schema="eousr"
table="TARIFF_ACCESSORIAL">
<composite-id name="id" class="com.*****.cc.objectlib.tariff.TariffAccessorialIdentity">
<key-property name="seqId" column="SEQ_ID" type="java.lang.Long"/>
<key-property name="tariffId" column="TARIFF_ID" type="java.lang.Long"/>
</composite-id>
<!-- properties deleted for brevity -->
<!-- associations -->
<!-- bi-directional many-to-one association to TariffState -->
<many-to-one
name="tariffState"
class="com.*****.cc.objectlib.tariff.TariffState"
not-null="true"
update="false"
insert="false">
<column name="TARIFF_ID"/>
</many-to-one>
</class>
</hibernate-mapping>
Is something like
Code:
<composite-id name="id" class="com.*****.cc.objectlib.tariff.TariffAccessorialIdentity">
<key-property name="seqId" column="SEQ_ID" type="java.lang.Long">
<generator class="sequence">
<param name="sequence">tariff_accessorial_seq</param>
</generator>
</key-property>
<key-property name="tariffId" column="TARIFF_ID" type="java.lang.Long">
<generator class="parent"/>
</key-property>
</composite-id>
or
Code:
<composite-id name="id" class="com.*****.cc.objectlib.tariff.TariffAccessorialIdentity">
<key-property name="seqId" column="SEQ_ID" type="java.lang.Long"/>
<key-property name="tariffId" column="TARIFF_ID" type="java.lang.Long"/>
<generator class="com.*****.cc.objectlib.tariff.IdentityGenerator">
<param name="child_sequence">tariff_accessorial_seq</param>
</generator>
</composite-id>
possible?
Is the other option to implement IdentifierGenerator or PersistentIdentifierGenerator and handle the key generation myself?
Thanks.