0

我有一个驱动程序类:

 public class Driver {

    private String driverId;
    private String driverName;

    //getter and setter

}

和一个 DriverEntry 类,用于存储驾驶员日常驾驶详细信息,DriverEntry 类具有 DriverEntryKey,其中包含 Driver 对象和 Date 对象。那么如何在 driver.hbm.xml 文件中映射这些文件呢?

 public class DriverEntry {

    private DriverEntryKey key;
    private String startTime;
    private String endTime;
    //getter and setter

}

    public class DriverEntryKey implements Serializable{

    private Driver driver;
    private Date date;


}
   <class name="Driver" table="driver" >
    <id name="driverId" column="driver_id">
    <generator class="assigned"/>
    </id>
    <property name="driverName" column="prod_name" length="20"/>
    </class>


    <class name="DriverEntry" table="DriverEntry" >
    <composite-id name="key" class="DriverEntryKey">
    <key-property name="driver" type=""></key-property>
    <key-property name="date" type=""></key-property>        
    </composite-id>
    </class>

那么我可以在里面填写什么维护驱动程序---主键到外键---在---> DataEntry 表?

4

2 回答 2

0
<class name="DriverEntry" >
        <composite-id name="key" class="DriverEntryKey">
            <key-many-to-one name="driver" class="Driver" column="driver_id"/>
            <key-property name="drivingDate" type="java.util.Date"></key-property>
        </composite-id>

        <property name="startTime" column="start_time" />
        <property name="endTime" column="end_time" />



    </class>
于 2013-10-18T14:48:14.993 回答
0

这是你想要达到的目标吗

<class name="DriverEntry">

<composite-id name="id" class="DriverEntryKey">
    <key-property name="driverId"/>
    <key-property name="date" type="date"/>        
</composite-id>

<property name="name"/>

<many-to-one name="driver" class="Driver">
    <column name="driverId"/>
    // all other columns
</many-to-one>
....

</class>

您将不得不根据您的要求稍微调整答案

于 2013-10-18T09:12:12.250 回答