簡體   English   中英

一對一的Hibernate映射

[英]Hibernate mapping for one-to-one

我有兩個綁定到Hibernate的類,無法確定將Drug條目映射到我的PrescribedDrug類的配置。

public class PrescribedDrug implements Serializable {

    protected int prescribedDrugId;
    private int drugId;
    protected String sig;
    protected int quantity;
    protected int refillNumber;
    protected Drug drugInfo;
    ...
}

public class Drug implements Serializable {
    protected int drugId;
    protected String name;
    protected double strength;
    protected String strengthUnits;
    ...
}

我的數據模型如下所示:

prescribed_drug             drug
----------                  --------------
prescribed_drug_id*         drug_id*
drug_id*                    name
sig                         ....
...

這是我的休眠配置:

<hibernate-mapping>
    <class name="org.example.smartgwt.shared.model.PrescribedDrug" table="prescribed_drug" lazy="false">

        <id name="prescribedDrugId" column="prescribed_drug_id">
            <generator class="assigned"/>
        </id>

        <property name="drugId">
            <column name="drug_id"/>
        </property>
        <property name="sig">
            <column name="sig"/>
        </property>
        <property name="quantity">
            <column name="quantity"/>
        </property>
        <property name="refillNumber">
            <column name="refill_number"/>
        </property>

        <one-to-one name="drugInfo" class="org.example.smartgwt.shared.model.Drug" lazy="false" />

    </class>
</hibernate-mapping>

<hibernate-mapping>
    <class name="org.example.smartgwt.shared.model.PrescribedDrug" table="prescribed_drug" lazy="false">

        <id name="drugId" column="drug_id">
            <generator class="assigned"/>
        </id>

        <property name="name">
            <column name="name"/>
        </property>
        <property name="strength">
            <column name="strength"/>
        </property>
        <property name="strengthUnits">
            <column name="strength_units"/>
        </property>
    </class>
</hibernate-mapping>

注意這里我嘗試使用一對一的方式PrescribedDrug.hbm.xml配置中映射我的Drug ,但是休眠狀態一直告訴我將Drug的字段添加到PrescribedDrug文件中...

在org.example.smartgwt.shared.model.PrescribedDrug上找不到字段[名稱]

葯物表中的條目是靜態的,包含處方葯的屬性。

謝謝。

在您的映射中,我看到您僅映射了PrescribedDrug。

將第二個映射文件類更改為Drug

<class name="org.example.smartgwt.shared.model.Drug" table="drug" lazy="false">

很明顯地在評論中給出了答案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM