Hi There,
I am under a deliverable deadline and I am having problems with my one to many mappings.
I have a parent table order with key orderid and purchaseditems table with foreign key orderid.
Problem: When I try to query the Order table, it fetches the associated purchaseditems once, in the process also updates the orderid in purchaseditems table with 0.
Hence the consecutive queries dont work.
Given below are the mappings please suggest what should I do.
Any help would be highly appreciated.
Thanks
-----------------------------------------------------
Mapping for Order class
-----------------------------------------------------
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="Order"
table="order">
<id
name="orderid" type="int" column="orderid">
<generator class="identity"/>
</id>
<set name="purchaseditems" lazy="true">
<key column="orderid"/>
<one-to-many class="PurchaseItems"/>
</set>
</class>
</hibernate-mapping>
-------------------------------------------------------------
Class definition of Order-------------------------------------------------------------
Code:
public class Order
{
private Set purchaseitems;
private int orderid;
public void setOrderid(int torderid)
{
this.orderid=torderid;
}
public int getOrderid()
{
return this.orderid;
}
public void setPurchaseditems(java.util.Set v)
{
this.purchaseditems=v;
}
public Set getPurchaseditems()
{
return this.purchaseditems;
}
}
------------------------------------------------------------------------
class definition of Purchaseditems------------------------------------------------------------------------
Code:
public class PurchasedItems
{
public void setItemid(java.lang.String titemid)
{
this.itemid=titemid;
}
public String getItemid()
{
return this.itemid;
}
public int getOrderid()
{
return this.orderid;
}
public void setOrderid(int id)
{
this.orderid=orderid;
}
}
---------------------------------------------------------------------
Mapping of PurchasedItems
--------------------------------------------------------------------
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="PurchasedItems" table="purchaseditems">
<property
name="itemid"
column="itemid"
/>
<property
name="orderid"
column="orderid"
/>
</class>
</hibernate-mapping>