1

我正在使用 Hibernate 3.0 为我的 POJO 类编写一个 order.hbm.xml 文件,如下所示

import java.util.Set;

public class OrderDAO 
{   
    private EmbeddedCustDAO embedCustID;

    private Set<String> custOrderSet;

    private String totalAmount;

    public EmbeddedCustDAO getEmbedCustID()
    {
        return embedCustID;
    }

    public void setEmbedCustID(EmbeddedCustDAO embedCustID)
    {
        this.embedCustID = embedCustID;
    }

    public Set<String> getCustOrderSet()
    {
        return custOrderSet;
    }

    public void setCustOrderSet(Set<String> custOrderSet) 
    {
        this.custOrderSet = custOrderSet;
    }

    public String getTotalAmount() 
    {
        return totalAmount;
    }

    public void setTotalAmount(String totalAmount) 
    {
        this.totalAmount = totalAmount;
    }
}

嵌入式/复合 ID 类是,

public class EmbeddedCustDAO
{
    private String customerName;

    private String custAddress;

    public String getCustomerName()
    {
        return customerName;
    }

    public void setCustomerName(String customerName)
    {
        this.customerName = customerName;
    }

    public String getCustAddress()
    {
        return custAddress;
    }

    public void setCustAddress(String custAddress) 
    {
        this.custAddress = custAddress;
    }
}

我写的 order.hbm.xml 文件是,

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC  
   "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="org.harish.dao.OrderDAO"
        table="order_table">
        <composite-id name="embedCustId"
            class="org.harish.dao.EmbeddedCustDAO">
            <key-property name="customerName"/>
            <key-property name="custAddress" />
        </composite-id>
        <set name="custOrderSet">
            <key column="??" />
            <element type="string" column="??"/>
        </set>
        <property name="totalAmount" />
    </class>
</hibernate-mapping>

我不确定如何在上面的 order.hbm.xml 中声明集合。我浏览了 Hibernate 3.0 Reference。它提到 Set 中的键列是 .hbm.xml 中定义的主键的列名。但是,对于复合 ID,列名是什么?Set 这里需要一对多的映射吗?

4

0 回答 0