2010-07-23 168 views
0

我有两个类与Hibernate绑定映射,我无法弄清楚将配置映射到药物条目到我的规定药物类。休眠映射一对一

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配置:

<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配置使用一到一个但休眠不断告诉我添加字段药物PrescribedDrug文件...

区[name]不org.example.smartgwt.shared找到。 model.PrescribedDrug

条目中药物表是静态的,包含处方药的性质。

谢谢。

+0

我不明白的是这'私人诠释drugId;'的'PrescribedDrug'类。 – 2010-07-24 00:39:01

+0

不应该在那里......我因为Hibernate而添加了它。但是我在最终版本中删除了它。我在映射中遇到了一些错误,由于@ hvgotcodes而得到修复。 – 2010-07-24 12:26:44

回答

0

摸索出答案的评论,显然....

+0

是的,它在开始的时候并不存在,比Hibernate告诉我要添加它。所以我做了。比它告诉我添加“名称”,这是毒品类中的另一个字段。 – 2010-07-23 22:57:55

+0

Hibernate怎么能知道我在处方中与哪个drug_id相关? – 2010-07-23 23:02:30

+0

@ code-gijoe你可以使用一个独特的多对一,如这里所展示的.... http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping。 html#mapping-declaration-onetoone – hvgotcodes 2010-07-23 23:05:18

1

在您的映射,我看见你只映射为PrescribedDrug。

更改你的第二映射文件类药物

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