"找不到“"的吸气剂错误 [英] " Could not find a getter for " Error
问题描述
尝试运行代码时出现错误.你们能帮忙吗?我已经附上了我的地图文件.这里的问题是,正在低于错误."org.hibernate.PropertyNotFoundException:在类bean.Employee中找不到用于eployeedetail的吸气剂"
I am getting error when I am trying to run my code. Can you guys Please help. I have attached my mapping files. The issue here is that, am getting below error. " org.hibernate.PropertyNotFoundException: Could not find a getter for eployeedetail in class bean.Employee "
这是我的员工班级
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
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
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>
推荐答案
问题出在 Employee.hbm.xml
中.每当您指定一对一标签时,都需要指定2个基本属性:
The problem is in Employee.hbm.xml
. Whenever you specify a one-to-one tag, you need to specify 2 basic attributes:
- 名称,代表属性的名称.在您的情况下,应为
Edetails
&不是eployeedetail
.这是获得成功的原因. - 类,它表示与该类一对一关联的类名称.您的情况应该是
EployeeDetails
.
- name which represents name of the property. In you case it should be
Edetails
& noteployeedetail
. THIS IS THE REASON YOU'RE GETTING THE EXCEPTION. - class which represents the class name which is associated as one-to-one with this class. In your case it should be
EployeeDetails
.
更改 Employee.hbm.xml
,将一对一标签属性 name 更改为 Edetails
&您的问题将得到解决.
Change Employee.hbm.xml
, change one-to-one tag attribute name to Edetails
& your problem will be solved.
这篇关于"找不到“"的吸气剂错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!