简体   繁体   中英

Bean property 'dipartmantId' is not readable or has an invalid getter method:

What did I do wrong here, I'm having the following error

Invalid property 'dipartmantId' of bean class [com.atlas.salesapplication.entity.Employee]: Bean property 'dipartmantId' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?

@Entity
@Table(name = "departmant")
public class Departmant {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Integer id;
    @Column(name = "name")
    private String name;

    @OneToMany(mappedBy = "departmantId")
    private List<Employee> employeeList;

    public List<Employee> getEmployeeList() {
        return employeeList;
    }

    public void setEmployeeList(List<Employee> employeeList) {
        this.employeeList = employeeList;
    }

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

    public Integer getId(){ return id; }

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

    public String getName(){ return name; }

    public Departmant(){}

    public Departmant(Integer id, String name){
        this.id = id;
        this.name = name;
    }

    @Override
    public String toString(){
        return name;
    }
}

Employee class as follows,

@Entity
@Table(name = "employee")
public class Employee {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Integer id;
    @Column(name = "firstname")
    @NotEmpty(message = "")
    @Size(min=3, message = "First name should ane minimum 3 letters.")
    private String firstName;
    @Column(name = "lastname")
    @NotEmpty(message = "")
    @Size(min=3, message = "Last name should ane minimum 3 letters.")
    private String lastName;
    @Column(name = "dob")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @NotNull(message = "Please enter a Date of Birth!")
    private Date dob;
    @Column(name = "nic")
    @NotEmpty(message = "")
    @Pattern(regexp = "([0-9]{9}[V|v|X|x])|([0-9]{12})",message = "Please enter valid email!")
    private String nic;
    @Column(name = "moblie")
    @NotEmpty(message = "")
    @Pattern(regexp = "((07)(0|1|2|5|6|7|8)[0-9]{7})",message = "Please enter valid mobile number!")
    private String mobile;
    @Column(name = "home")
    @NotEmpty(message = "")
    @Pattern(regexp = "([0-9]{10})",message = "Please enter valid phone number!")
    private String home;
    @Column(name = "addressline1")
    @NotEmpty(message = "")
    private String addressLine1;
    @Column(name = "addressline2")
    private String addressLine2;
    @Column(name = "city")
    @NotEmpty(message = "")
    private String city;
    @Column(name = "image")
    private byte [] image;
    @Column(name = "status")
    private boolean status;

    @ManyToOne
    @JoinColumn(name ="gender_id")
    private  Gender genderId;

    @ManyToOne
    @JoinColumn(name = "designation_id")
    private Designation designationId;

    @ManyToOne
    @JoinColumn(name = "departmant_id")
    private Departmant departmantId;

    public Departmant getDepartmantId() {
        return departmantId;
    }

    public void setDepartmantId(Departmant departmantId) {
        this.departmantId = departmantId;
    }

    public Designation getDesignationId() {
        return designationId;
    }

    public void setDesignationId(Designation designationId) {
        this.designationId = designationId;
    }

    public Gender getGenderId() {
        return genderId;
    }

    public void setGenderId(Gender genderId) {
        this.genderId = genderId;
    }

    public boolean isStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }

    public Employee() {
    }

    public Integer getId() {
        return id;
    }

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

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public Date getDob() {
        return dob;
    }

    public void setDob(Date dob) {
        this.dob = dob;
    }

    public String getNic() {
        return nic;
    }

    public void setNic(String nic) {
        this.nic = nic;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getHome() {
        return home;
    }

    public void setHome(String home) {
        this.home = home;
    }

    public String getAddressLine1() {
        return addressLine1;
    }

    public void setAddressLine1(String addressLine1) {
        this.addressLine1 = addressLine1;
    }

    public String getAddressLine2() {
        return addressLine2;
    }

    public void setAddressLine2(String addressLine2) {
        this.addressLine2 = addressLine2;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public byte[] getImage() {
        return image;
    }

    public void setImage(byte[] image) {
        this.image = image;
    }

    public Employee(Integer id, String firstName, String lastName, String nic, String mobile, String home, Date dob, String addressLine1, String addressLine2, String city, byte[] image){
        this.id = id;
        this.firstName = firstName;
        this.lastName = lastName;
        this.nic = nic;
        this.mobile = mobile;
        this.home = home;
        this.dob = dob;
        this.addressLine1 = addressLine1;
        this.addressLine2 = addressLine2;
        this.city = city;
        this.image = image;
    }


    @Override
    public String toString(){
        return firstName+ " "+lastName;
    }
}

According to the error you provided:

Invalid property 'dipartmantId' of bean class [com.atlas.salesapplication.entity.Employee]: Bean property 'dipartmantId' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?

The dipartmantId property from Employee class is trying to be accessed. There seems to be a typo since the property in Employee class is really called departmantId .

Make a search in your code for uses of dipartmantId and change it to departmantId

You have a lot of different spelling errors in your code. I'd first correct all those and I bet your error goes away (and some others also):

  • rename all variations of departmant to department
  • rename moblie to mobile
  • find dipartmantId in your code and rename it to departmentId
  • consider naming the column that holds the email email instead of noc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM