gpt4 book ai didi

java - 在 Hibernate 映射中将集合转换为列表

转载 作者:行者123 更新时间:2023-12-01 12:56:04 24 4
gpt4 key购买 nike

以下是我在BillDetails中的pojo类(class)我用过billProductDetailses放。现在不再使用 Set 我想使用 List。为此我改变了 BillDetails.hbm.xml但我在映射到列表时遇到问题。

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
}

在 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>

这里我想使用List而不是Set所以我添加了 private List<BillProductDetails> billProductList = new ArrayList<BillProductDetails>();BillDetails

在 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>

我想知道应该是什么 <key><column name="??" not-null="true" /><index column="??"/>

最佳答案

在这种情况下您可以使用 Bag 映射。引用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>

关于java - 在 Hibernate 映射中将集合转换为列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23883589/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com