zoukankan      html  css  js  c++  java
  • org.hibernate.PropertyNotFoundException: Could not find a getter for employee in class com.itcast.f_hbm_oneToMany.Department

    <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 + "]";
        }
    
    }
  • 相关阅读:
    栈的使用
    学习
    JS中常用的工具类
    AOP的相关概念
    Git-用git同步代码
    权限管理3-整合Spring Security
    权限管理2-开发权限管理接口
    权限管理1-需求描述
    使用Canal作为mysql的数据同步工具
    使用存储过程在mysql中批量插入数据
  • 原文地址:https://www.cnblogs.com/johnsonwei/p/5991497.html
Copyright © 2011-2022 走看看