首页 > 代码库 > hibernate出现 org.hibernate.PropertyNotFoundException: field [departmen] not found on cn.itcast.hibernate.domain.Employee1错误

hibernate出现 org.hibernate.PropertyNotFoundException: field [departmen] not found on cn.itcast.hibernate.domain.Employee1错误

hibernate出现 org.hibernate.PropertyNotFoundException: field [departmen] not found on cn.itcast.hibernate.domain.Employee1错误

出现这种错误是因为,实体类的配置文件(ClassName.hbm.xml)中的属性名和类中的属性名不一致造成的,检查并修改就可解决

比如:

类有如下属性:

private int id;

private String name;
private Department department;

配置文件:

<class name="Employee1">

        <id name="id">
            <generator class="native"/>
        </id>

        <property name="name"/>
        <many-to-one name="depart" column="depart_id"/>
    </class>

///////////////////////////

如上就会出现错误,因为多对一关系中的name的值depart和类的属性department没对应,就报错了

hibernate出现 org.hibernate.PropertyNotFoundException: field [departmen] not found on cn.itcast.hibernate.domain.Employee1错误