I have 2 questions.
The first question is:
JobCart:
ID (PK)
HeatKitModel (FK) - to HeatKits table, ItemNumber column
ProductID (FK) - to Product table
Product:ID (PK)
HeatKitTableName (FK) - to HeatKits table, TableName column
HeatKits:TableName (PK)
ItemNumber (PK)
HeatingOption (FK)
How can I write a mapping for JobCart (especially if I want to have a HeatKit object inside of JobCart)?
The other key to HeatingOption table is in the Product table.
Code:
<hibernate-mapping>
<class name="com.abc.JobCart" table="lcpjbcp">
<id name="id" column="ID" unsaved-value="0">
<generator class="native" />
</id>
<many-to-one name="product"
class="com.abc.Product" column="productId"
not-null="true" fetch="join" lazy="false" />
</class>
</hibernate-mapping>
Second question is:
HeatKits has a one-to-one relationship with HeatingOption table through heatingOption column (FK).
However, HeatingOption has 2 PK (Composite Key) - ID and type.
The database designer says that all HeatKit will always have type="ELE", so no need to repeat the column.
How can I have a HeatingOption object inside of the HeatKit object?
Currently, I just grab the heatingOption as a string, and then run another query to get the HeatingOption object.
Code:
<hibernate-mapping>
<class name="com.abc.HeatKit" table="lcphktp">
<composite-id>
<key-property name="tableName" />
<key-property name="itemNumber" />
</composite-id>
<property name="heatingOption"/>
</class>
</hibernate-mapping>
<class name="com.abc.HeatingOption"
table="lcphopp">
<composite-id>
<key-property name="id" />
<key-many-to-one name="heatingType"
class="com.abc.HeatingType"
column="type" lazy="false"/>
</composite-id>
<property name="description" />
</class>