1

I am writing an order.hbm.xml file for my POJO class as below using Hibernate 3.0

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;
    }
}

The Embedded/ Composite ID class is,

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;
    }
}

The order.hbm.xml file that I have written is,

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

I am not sure how to declare the set in the order.hbm.xml above. I went through the Hibernate 3.0 Reference. It mentions the key column in the Set to be column name of the Primary Key defined in the .hbm.xml. But, with a composite ID what would be the Column name? Is a one-to-many mapping required here for the Set?

Harish
  • 181
  • 1
  • 3
  • 11

0 Answers0