Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java hibernate-spring/bean映射集_Java_Hibernate_Spring_Mapping - Fatal编程技术网

Java hibernate-spring/bean映射集

Java hibernate-spring/bean映射集,java,hibernate,spring,mapping,Java,Hibernate,Spring,Mapping,我基本上是一个刚开始使用SpringHibernate的人,我一直在努力让它工作 我有这样一个数据模型: patient prescription ---------- -------------- patient_id* prescription_id* first_name patient_id* last_name date ... <bean id

我基本上是一个刚开始使用SpringHibernate的人,我一直在努力让它工作

我有这样一个数据模型:

patient                prescription
----------             --------------
patient_id*            prescription_id*
first_name             patient_id*
last_name              date
...
    <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>
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;
}
}
我使用SpringBeans和hibernate模板来定义会话/hibernatetemplate和dao,如下所示:

patient                prescription
----------             --------------
patient_id*            prescription_id*
first_name             patient_id*
last_name              date
...
    <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>
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;
}
}
(类似于处方药的更简单的事情)

困扰我的是私人设置PatientDescriptions成员。下面是我的patient类的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>

谢谢

显而易见的答案是,您的hibernate映射没有提到
处方
类,因此hibernate不知道如何处理它

假设情况并非如此,而您只是没有向我们显示映射,那么下一个最明显的答案是:

<one-to-many class="Prescription"/>

很明显,hibernate映射没有提到
处方
类,因此hibernate不知道如何处理它

假设情况并非如此,而您只是没有向我们显示映射,那么下一个最明显的答案是:

<one-to-many class="Prescription"/>

谢谢!完全限定的类名是我的问题。花了一天时间寻找这样一个简单的答案。现在它工作了!谢谢!完全限定的类名是我的问题。花了一天时间寻找这样一个简单的答案。现在它工作了!