org.hibernate.PropertyNotFoundException: Could not find a getter for employee in class com.itcast.f_

Posted 达哥的博客

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了org.hibernate.PropertyNotFoundException: Could not find a getter for employee in class com.itcast.f_相关的知识,希望对你有一定的参考价值。

<hibernate-mapping package="com.itcast.f_hbm_oneToMany">
    <class name="Department" table="department">

        <!--generator主键生成策略 -->
        <id name="id">
            <generator class="native" />
        </id>
        <property name="name" />
        <set name="employees">
            <key column="departmentID"></key>
            <one-to-many class="Employee"/>
        </set>
    </class>
</hibernate-mapping>

由于上面这个映射文件里我employees少写了s,造成了错误。映射文件里的属性是跟实体Department里的属性是一一对应的。实体Department如下:

public class Department {
    private Integer id;
    private String name;

    private Set<Employee> employees = new HashSet<Employee>(); // 关联的很多员工

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Set<Employee> getEmployees() {
        return employees;
    }

    public void setEmployees(Set<Employee> employees) {
        this.employees = employees;
    }

    @Override
    public String toString() {
        return "[Department: id=" + id + ", name=" + name + "]";
    }

}

 

以上是关于org.hibernate.PropertyNotFoundException: Could not find a getter for employee in class com.itcast.f_的主要内容,如果未能解决你的问题,请参考以下文章