Ahmed Tawila Ahmed Tawila -4 years ago 103
MySQL Question

REST web service returns a field that does not exist in the underlying SQL query

When I try to access the following REST service, it returns all data plus a field that does not exist in the "SupplierPayment" entity class "customerId".

@GET
@Produces(MediaType.APPLICATION_JSON)
public List<SupplierPayment> getAllSupplierPaymentsService() {
return (ArrayList<SupplierPayment>) supplierPaymentDao.getAllSupplierPayments();
}


Here is the getAllSupplierPayments() method:

public List<SupplierPayment> getAllSupplierPayments() {
String query = "SELECT * FROM supplierpayment";
return (ArrayList<SupplierPayment>) getJdbcTemplate().query(query,
new BeanPropertyRowMapper<SupplierPayment>(SupplierPayment.class));
}


Here are all the fields in the "SupplierPayment" class:

private Integer supplierPaymentId;
private BigDecimal amount;
private Integer purchaseInvoiceId;
private Integer supplierId;
private Integer paymentMethodId;
private String description;
private Integer checkId;
private Integer fromBankAccountId;
private Integer toBankAccountId;
private String creditCardNo;
private Timestamp created;
private Integer createdBy;


When I debug, I find that the ArrayList of the web service does not return that field, then somehow I find that field in the response.

I tried truncating and dropping the table and adding the columns one after the other. What I found is the field is returned in the response only when I add the column "supplierId" to the table and its value is the same of "supplierId". I think the column "customerId" existed before and I dropped it.

Answer Source

I found that the following getter and setter existed in the SupplierPayment entity class because of the previously existing column in the table:

public Integer getCustomerId() {
    return supplierId;
}

public void setCustomerId(Integer customerId) {
    this.supplierId = customerId;
}

By removing them, the problem was solved.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download