hibernate - spring / bean mapping set

我几乎是一个带有spring-hibernate的新手,我一直试图让它工作。 我有这样的数据模型:
patient                prescription
----------             --------------
patient_id*            prescription_id*
first_name             patient_id*
last_name              date
...
我正在使用带有hibernate模板的spring bean来定义我的session / hibernatetemplate和dao,如下所示:
    <bean id="mySessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="myDataSource" />
    <property name="mappingResources">
        <list>
            <value>./org/example/smartgwt/shared/model/prescription.hbm.xml</value>
            <value>./org/example/smartgwt/shared/model/patient.hbm.xml</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <value>hibernate.dialect=org.hibernate.dialect.HSQLDialect</value>
    </property>
</bean>

<!-- Wrapper for low-level data accessing and manipulation -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
    <property name="sessionFactory">
        <ref bean="mySessionFactory" />
    </property>
</bean>

<!--  -->

<bean id="patientDao" class="org.example.smartgwt.server.data.PatientDao">
    <property name="hibernateTemplate">
        <ref bean="hibernateTemplate" />
    </property>
</bean>

<bean id="prescriptionDao" class="org.example.smartgwt.server.data.PrescriptionDao">
    <property name="hibernateTemplate">
        <ref bean="hibernateTemplate" />
    </property>
</bean>
有一段时间我只有病人的桌子,一切都很好。但后来我决定添加一个使用patient_id类型的外键的处方。基本上我有2个POJO模型对象,如下所示:
public class Patient implements Serializable {

///////////////////////////////////////////////////////////////////////////
// Data members
///////////////////////////////////////////////////////////////////////////
private static final long serialVersionUID = 1L;
private int    patientId;
private String firstName;
private String lastName;
private Date   birthDate;
private String address;
private String phone;

private Set patientPrescriptions;

public Patient() {}

public void setPatientId(int patientId) {
    this.patientId = patientId;
}

public int getPatientId() {
    return patientId;
}

public void setFirstName(String firstName) {
    this.firstName = firstName;
}

public String getFirstName() {
    return firstName;
}

public void setLastName(String lastName) {
    this.lastName = lastName;
}

public String getLastName() {
    return lastName;
}

public void setBirthDate(Date birthDate) {
    this.birthDate = birthDate;
}

public Date getBirthDate() {
    return birthDate;
}

public void setAddress(String address) {
    this.address = address;
}

public String getAddress() {
    return address;
}

public void setPhone(String phone) {
    this.phone = phone;
}

public String getPhone() {
    return phone;
}

public void setPatientPrescriptions(Set patientPrescriptions) {
    this.patientPrescriptions = patientPrescriptions;
}

public Set getPatientPrescriptions() {
    return patientPrescriptions;
}
}
(处方也比较简单)。 困扰我的是私人Set patientPrescriptions会员。这是我的患者类的hbm.xml映射。
<hibernate-mapping>
<class name="org.example.smartgwt.shared.model.Patient" table="patient" lazy="true">
    <id name="patientId" column="patient_id">
        <generator class="increment"/>
    </id>

    <property name="firstName">
        <column name="first_name"/>
    </property>
    <property name="lastName">
        <column name="last_name"/>
    </property>
    <property name="birthDate">
        <column name="birth_date"/>
    </property>
    <property name="address">
        <column name="address"/>
    </property>
    <property name="phone">
        <column name="phone"/>
    </property>

    <set name="patientPrescriptions" cascade="all">
        <key column="patient_id"/>
        <one-to-many class="Prescription"/>
    </set>

</class>
一旦我在patient.hbm.xml映射文件中引用它,我就会收到错误。   org.springframework.beans.factory.BeanCreationException:在文件[C: eclipse workspace smart-gwt WebContent WEB-INF resources hibernate-beans.xml]中定义名称为'prescriptionDao'的bean创建错误:无法解析设置bean属性'hibernateTemplate'时引用bean'hibernateTemplate';嵌套异常是org.springframework.beans.factory.BeanCreationException:在文件[C: eclipse workspace smart-gwt WebContent WEB-INF resources hibernate-beans.xml]中定义名称为'hibernateTemplate'的bean时出错:设置bean属性'sessionFactory'时无法解析对bean'mySessionFactory'的引用;嵌套异常是org.springframework.beans.factory.BeanCreationException:在文件[C: eclipse workspace smart-gwt WebContent WEB-INF resources hibernate-beans.xml]中定义名称为'mySessionFactory'的bean时出错:调用init方法失败;嵌套异常是org.hibernate.MappingException:关联引用未映射的类:处方 为什么我得到此Set的未映射错误?如果我从我的hbm.xml中删除它,我可以用我的会话完成我的所有事情。请求dao对象时有什么特别的事吗?这是我用来获取我的代码的代码。
        Resource resource = new FileSystemResource("./hibernate-beans.xml");
        BeanFactory factory = new XmlBeanFactory(resource);
        PrescriptionDao prescriptionDao = (PrescriptionDao)factory.getBean("prescriptionDao");
        PatientDao clientDao = (PatientDao) factory.getBean("patientDao");
谢谢     
已邀请:
很明显的答案是你的hibernate映射没有提到
Prescription
类,所以Hibernate不知道如何处理它。 假设情况并非如此,而你只是没有向我们展示映射,那么下一个最明显的答案就是:
<one-to-many class="Prescription"/>
class
属性应该是一个完全限定的类名,
Prescription
不是。也许它应该是这样的:
<one-to-many class="org.example.smartgwt.shared.model.Prescription"/>
    

要回复问题请先登录注册