2

I am writing a Spring boot application linked to MySQL, in one of my packages:

com.Employee.DataManagement.salaries

enter image description here

I misspelled a property's name:

@Column(name = "from_date")
java.sql.Date fromeDate

As you can see, there is an extra "e" in the name. But I didn't realize it at that time and run the main java file(the one with annotation @SpringBootApplication) for a few times. Then I removed the extra "e" and the property becomes this:

@Column(name = "from_date")
java.sql.Date fromDate

Setter and Getter looks like this:

public Date getFromeDate() {
    return fromDate;
}

public void setFromeDate(Date fromDate) {
    this.fromDate = fromDate;
}

However, when I run the java file again, the old property name won't go away. The are some screenshot:

When I use GET and get the response, the from date in JSON always display as the previous name. enter image description here

When I want to POST new data into the database, the example given by Swagger is like this: enter image description here

But in the RequestBody I can ignore the misspell property and only use the correct one, write like this:

{ "embeddedKeyId": { "employee": { "emp_no": 123123 }, "fromDate": "2012-10-27", }, "salary": 450, "toDate": "2333-08-09" }

But the output will still display as the old property name.

I searched through the project to see if I forgot to change some property name, but I got nothing.

Lastly, here is the screenshot of the salaries table in database enter image description here

Yingcai
  • 61
  • 8
  • How you getters / setters look like? And why dont you simply remove misspelled column from db https://stackoverflow.com/a/13968514/1032167 or even wipe your db and let hibernate to recreate it? – varren Oct 10 '17 at 16:10
  • I use the @Column("from_date") so in the database, the mapped column name is always "from_date" – Yingcai Oct 10 '17 at 18:11
  • fix your getters names `getFromeDate => getFromDate` and setter `setFromeDate => setFromDate` – varren Oct 10 '17 at 18:12
  • By default Spring uses Jackson to work with json and Jackson by default will use getters and setters and not field names so json field names come from `getters name -> field name` conversion with rules based on JavaBeans Specification. You could use `@JsonProperty("somename")` to override this behavior, but it is not needed in your case. – varren Oct 10 '17 at 18:25

1 Answers1

0

The answer is cited from varren's answer

Change setter and getter from:

public Date getFromeDate() {
  return fromDate;
}

public void setFromeDate(Date fromDate) {
  this.fromDate = fromDate;
}

To:

public Date getFromDate() {
  return fromDate;
}

public void setFromDate(Date fromDate) {
  this.fromDate = fromDate;
}

Without "e".

Yingcai
  • 61
  • 8