나는 봄 - 동면 (spring-hibernate)과 함께 꽤 많은 newb이고 나는 그것을 작동 시키려고 노력하고있다. 나는이 같은 내 세션/HibernateTemplate에와 DAO를 정의하는 최대 절전 모드 템플릿 봄 콩을 사용하고hibernate - spring/bean 매핑 세트
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>
를 I 환자 테이블 만 있고 모두 괜찮 았어. 그런 다음 처방을 추가하여 patient_id 유형의 외래 키를 사용하기로 결정했습니다. 기본적으로 나는 다음과 같은 POJO 모델 객체 2 개를 가지고있다.
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;
}
}
(처방과 비슷하다).
저를 괴롭히는 것은 개인 설정 환자 명세서입니다 회원입니다. 내 환자 클래스에 대한 내 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 : 이름을 가진 bean을 생성 오류 'prescriptionDao'파일 [C에서 정의 : \ 이클립스 \ 작업 \ 스마트 GWT \의 WebContent \ WEB-INF \ 리소스 \ 최대 절전 모드 콩 .xml] : bean 속성 'hibernateTemplate'을 설정하는 동안 bean 'hibernateTemplate'에 대한 참조를 해결할 수 없습니다. 중첩 예외는 org.springframework.beans.factory.BeanCreationException입니다 : 'C : \ eclipse \ workspace \ smart-gwt \ WebContent \ WEB-INF \ resources \ hibernate-beans.xml] 파일에 정의 된'hibernateTemplate ' : 'sessionFactory'빈 속성을 설정하는 동안 'mySessionFactory'빈에 대한 참조를 확인할 수 없습니다. 중첩 예외는 org.springframework.beans.factory.BeanCreationException입니다 : 'C : \ eclipse \ workspace \ smart-gwt \ WebContent \ WEB-INF \ resources \ hibernate-beans.xml] 파일에 정의 된'mySessionFactory ' : init 메소드의 호출이 실패했습니다.
가 왜이 세트에 대한 매핑되지 않은 에러가 발생합니까 처방 : 협회 참조 매핑되지 않은 클래스 : 중첩 된 예외 org.hibernate.MappingException입니까? hbm.xml에서 제거하면 세션을 통해 모든 것을 할 수 있습니다. DAO 객체를 요청하는 동안 할 특별한 것이 있습니까? 내 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
클래스의 언급을하지 않습니다 것을 당신
Thx! 정규화 된 클래스 이름이 내 문제였습니다. 그런 단순한 대답을 찾기 위해 하루를 보냈습니다. 이제 작동합니다! –