Composite Foreign Key Auditing
gorf May 1, 2013 9:55 AMI'm working with a legacy database that uses a composite foreign key to a unique composite key of another table. The tables look like the following:
Contract
-contractId
-playerId
-sequenceId
The contractId column is the primary key.
The playerId and sequenceId combine to form a unique key.
ContractCriteria
-contractCriteriaId
-playerId
-sequenceId
ContractCriteria has a foreign key back to Contract via its playerId and sequenceId columns.
A Contract can have many ContractCriteria.
My hbm mappings look like this:
{code:xml}
<class name="Contract" table="Contract">
<id name="contractId" type="long" column="contractId">
<generator class="identity" />
</id>
<properties name="playerAndSequenceId" unique="true" update="false">
<many-to-one name="player" class="Player" column="playerId" />
<property name="sequenceId" type="long" column="sequenceId" />
</properties>
<set name="contractCriterias" inverse="true" cascade="all-delete-orphan">
<key property-ref="playerAndSequenceId">
<column name="playerId" />
<column name="sequenceId" />
</key>
<one-to-many class="ContractCriteria" />
</set>
</class>
{code}
{code:xml}
<class name="ContractCriteria" table="ContractCriteria">
<id name="contractCriteriaId" type="long" column="contractCriteriaId">
<generator class="identity" />
</id>
<many-to-one name="contract" class="Contract" property-ref="playerAndSequenceId">
<column name="playerId" />
<column name="sequenceId" />
</many-to-one>
</class>
{code}
My classes look like this:
{code:java}
@Audited
public class Contract {
private Long contractId;
private Player player;
private Long sequenceId;
private Set<ContractCriteria> contractCriterias;
/* Getters / Setters */
}
{code}
{code:java}
@Audited
public class ContractCriteria {
private Long contractCriteriaId;
private Contract contract;
/* Getters / Setters */
}
{code}
When I update one of the ContractCriteria objects in the set belonging to Contract and save the Contract, then everything works as I expect, except the audit table for ContractCriteria is not correct. It is inserting a null value for the sequenceId inside ContractCriteria_AUD.
Is there some additional audit configuration I need to do to make it write to that sequenceId column in the audit table? Maybe an extra annotation somewhere in my classes?