I have an
Order_Headers schema that has PK
order_id. I also have have another table
Order_Addresses that has the same PK as the
Order_Headers table, it also has a FK constraint on the
order_id column of the
Order_Addresses table referencing the
order_id column in the
Order_Headers table.
I have 2 classes OrderHeader and OrderAddress and I have the following entries in the mappings,
Code:
<class name="OrderHeader" schema="user" table="ORDER_HEADERS">
<id name="orderId" type="long" column="ORDER_ID" length="22" >
<generator class="sequence">
<param name="sequence">ORDER_SEQ</param>
</generator>
</id>
<property name="sentFlag" type="string" column="SENT_FLAG" length="1" />
<one-to-one name="orderAddress" constrained="true" class="OrderAddress" cascade="all"/>
</class>
<class name="OrderAddress" schema="user" table="ORDER_HEADERS">
<id name="addressId" column="ORDER_ID">
<generator class="foreign">
<param name="property">orderHeader</param>
</generator>
</id>
<property name="line1" type="string" column="LINE1" length="50" />
<property name="line2" type="string" column="LINE2" length="50" />
<one-to-one constrained="true" name="orderHeader" class="OrderHeader" />
</class>
But I get the following error when trying to save a OrderHeader object,
org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property: orderHeaderWhat do I have to do to create the associations correctly?