可能重复:
Hibernate - PropertyNotFoundException: Could not find a getter for
我在尝试运行代码时遇到错误。你们能帮忙吗?我附上了我的映射文件。这里的问题是,我得到低于错误。 “org.hibernate.PropertyNotFoundException:在类bean.Employee中找不到eployeedetail的getter”
这是我的员工类
package bean;
import bean.EployeeDetails;
public class Employee {
int EmpId;
String name;
String phone;
EployeeDetails Edetails;
public EployeeDetails getEdetails() {
return Edetails;
}
public void setEdetails(EployeeDetails eDetails) {
Edetails = eDetails;
}
和其他吸气者和安装者。
EployeeDetails.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="bean.EployeeDetails" table="eployeedetail">
<id name="EmpId">
<column name="employee_id"/>
<generator class="foreign" >
<param name="property">eployee</param>
</generator>
</id>
<one-to-one name="eployee" class="bean.Employee" constrained="true"></one-to-one>
<property name="Address" column="ADDRESS"/>
</class>
</hibernate-mapping>
Employee.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="bean.Employee" table="eployee">
<id name="EmpId" column="employee_id">
<generator class="native" />
</id>
<one-to-one name="eployeedetail" class="bean.EployeeDetails"/>
<property name="name" column="NAME"/>
<property name="phone" column="PHONE"/>
</class>
</hibernate-mapping>
答案 0 :(得分:1)
从
更改您的代码 EployeeDetails Edetails;
此
EployeeDetails Edetails = new EployeeDetails();
答案 1 :(得分:1)
问题出在Employee.hbm.xml
。每当您指定一对一标记时,您需要指定2个基本属性:
Edetails
&amp;不是eployeedetail
。 这是您获得例外的原因。 EployeeDetails
。更改Employee.hbm.xml
,将一对一标记属性名称更改为Edetails
&amp;你的问题将得到解决。