I am using Hibernate 2.1.2 with SAPDB 7.4.
The problem here is that I am unsure about terminology as it pertains to combination keys, surrogate keys etc. Here is the table structure I am dealing with.
I have an ORDERS table with Primary Key ORDERID and an ORDERLINEITEMS table with Primary Key of ORDERID and LINEITEMID.
Code:
TABLE ORDERS
ORDERID INTEGER PK
...
...
TABLE ORDERLINEITEMS
ORDERID INTEGER PK
LINEITEMID INTEGER PK
...
...
The Order object has the ORDERID provided to it by a sequence with the following mapping. The mapping from the Order object to the LineItem object is a one-to-many relationship.
Code:
<hibernate-mapping>
<class name="com.foo.bar.beans.order.Order" table="ORDERS" dynamic-update="false" dynamic-insert="false">
<id name="orderId" column="ORDERID" type="java.lang.Long" unsaved-value="null">
<generator class="sequence">
<param name="sequence">SEQ_ORDERID</param>
</generator>
</id>
...
...
<set name="assignedItemList" lazy="false" inverse="false" cascade="save-update" sort="unsorted" order-by="LINEITEMID">
<key column="LINEITEMID"/>
<one-to-many class="com.foo.bar.beans.order.LineItem"/>
</set>
</class>
</hibernate-mapping>
I think I sort of have a grasp on the situation till this point. But I am confused as to how I should map the LineItem object. I am assuming that the
LineItem object will need an
orderId attribute because of the nature of Hibernate as opposed to a regular OO structure where you need not have it if you are assigning the items to an Order object in a list. The cascade="save-update" from the Order object should tell Hibernate to save/update each individual line. But how does one go about mapping the LineItem object into LineItem.hbm.xml.
The object structure is as follows:
Code:
public class LineItem
implements Serializable
{
private Long orderId = null;
private Long lineItemId = null;
public Long getOrderId()
{
return orderId;
}
public void setOrderId(Long orderId)
{
this.orderId = orderId;
}
public Long getLineItemId()
{
return lineItemId;
}
public void setLineItemId()
{
this.lineItemId = lineItemId;
}
...
...
}
I am using XDoclet to generate the config file. Any help is greatly appreciated.
TIA