Reputation: 5327
Following are my pojo classes in BillDetails
I used billProductDetailses
Set.
Now insted of using Set I would Like to use List.
For that I am changed in BillDetails.hbm.xml
but I am facing problem while mapping in to list.
public class BillDetails implements java.io.Serializable {
private Long billNo;
private CustomerDetails customerDetails;
private Float subTotal;
private Float vat;
private Float total;
private String paymentType;
private String status;
private Timestamp addDate;
private Set<BillProductDetails> billProductDetailses = new HashSet(0);
//getter and setter
}
public class BillProductDetails implements java.io.Serializable {
private BillProductDetailsId id;
private ProductDetails productDetails;
private BillDetails billDetails;
private long qty;
private float unitPrice;
private float sellingPrice;
private Integer discountPercent;
//getter and setter
}
public class BillProductDetailsId implements java.io.Serializable {
private long productId;
private long billNo;
//getter and setter
}
In BillDetails.hbm.xml
<hibernate-mapping>
<class name="iland.hbm.BillDetails" table="bill_details" catalog="retail_shop">
<id name="billNo" type="java.lang.Long">
<column name="bill_no" />
<generator class="identity"></generator>
</id>
<many-to-one name="customerDetails" class="iland.hbm.CustomerDetails" fetch="join">
<column name="customer_id" not-null="true" />
</many-to-one>
<property name="subTotal" type="java.lang.Float">
<column name="sub_total" precision="10" />
</property>
<property name="vat" type="java.lang.Float">
<column name="vat" precision="10" />
</property>
<property name="total" type="java.lang.Float">
<column name="total" precision="10" />
</property>
<property name="paymentType" type="string">
<column name="payment_type" length="30" not-null="true" />
</property>
<property name="status" type="string">
<column name="status" length="20" />
</property>
<property name="addDate" type="timestamp">
<column name="add_date" length="19" not-null="true" />
</property>
<set name="billProductDetailses" table="bill_product_details" inverse="true" lazy="false" fetch="join">
<key>
<column name="bill_no" not-null="true" />
</key>
<one-to-many class="iland.hbm.BillProductDetails" />
</set>
</class>
</hibernate-mapping>
Here I would like to use List instead of Set
So I added
private List<BillProductDetails> billProductList = new ArrayList<BillProductDetails>();
In BillDetails
And In hbm.xml
<list name="billProductList" table="bill_product_details" inverse="true" lazy="false" fetch="join">
<key>
<column name="??" not-null="true" />
</key>
<index column="??"/>
<one-to-many class="iland.hbm.BillProductDetails" />
</list>
I would like to know what should be
<key><column name="??" not-null="true" />
and <index column="??"/>
Upvotes: 0
Views: 1214
Reputation: 8499
you can use Bag mapping in this case. Ref http://www.javatpoint.com/mapping-bag-in-collection-mapping
<bag name="billProductDetailses" table="bill_product_details" lazy="false" cascade="all">
<key>
<column name="bill_no"/>
</key>
<one-to-many class="iland.hbm.BillProductDetails" />
</bag>
Upvotes: 1