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

I have a jsp file as follows. I use this jsp file to store the Stock information entered by the user. For each input, I use spring form tag to bind a property of this object / bean.

<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

    <h1>add Stock</h1>

        <form:form action="addStock" modelAttribute="stock" method="POST">
        
            <table>
                <tbody>
                
                    <tr>
                        <td><label>Base Rate Of Return:</label></td>
                        <td><form:input path="baseRateOfReturn" /></td>
                    </tr>
                
                    <tr>
                        <td><label>Asset Code:</label></td>
                        <td><form:input path="code" /></td>
                    </tr>
                
                    <tr>
                        <td><label>Asset Label:</label></td>
                        <td><form:input path="label" /></td>
                    </tr>

                    <tr>
                        <td><label>Quarterly Dividend:</label></td>
                        <td><form:input path="quarterlyDividend" /></td>
                    </tr>
                    

                    
                    <tr>
                        <td><label>Price:</label></td>
                        <td><form:input path="sharePrice" /></td>
                    </tr>
                    
                    <tr>
                        <td><label>Beta:</label></td>
                        <td><form:input path="beta" /></td>
                    </tr>
                    
                    <tr>
                        <td><label></label></td>
                        <td><input type="submit" value="Save"/></td>
                    </tr>

                
                </tbody>
            </table>
        
        
        </form:form>
        


</body>
</html>

now I meet an exception. The key information for this exception is as follows.

Invalid property "code" of bean class [pojo.Stock]: Bean property "code" is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?

I went back to see my Stock class, and found that the class really didn"t define getter and setter method for code. As follows:

package pojo;

public class Stock extends Investment {
    private Double sharePrice;
    private Double beta;// risk measurement beta

    public Stock() {
    }

    public Stock(String code, String label, Double quarterlyDividend, Double baseRateOfReturn, Double sharePrice,
            Double beta) {
        super(code, label, quarterlyDividend, baseRateOfReturn);
        this.sharePrice = sharePrice;
        this.beta = beta;
    }


    
    public Double getSharePrice() {
        return sharePrice;
    }

    public void setSharePrice(Double sharePrice) {
        this.sharePrice = sharePrice;
    }

    public Double getBeta() {
        return beta;
    }

    public void setBeta(Double beta) {
        this.beta = beta;
    }

    @Override
    public String accountType() {
        return "S";
    }

    @Override
    public Double riskMeasure() {
        return Math.round(100 * beta) / 100d;
    }


}

the point is that Stock is a subclass of Investment, and now that the getter and setter methods of code are defined in Investment, they should not be overridden in the subclass Stock.

so how can you resolve this exception without overriding the getCode and setCode methods?

here is the pojo class of the parent class Investment and its parent class Asset.

package pojo;

public abstract class Investment extends Asset {
    private Double quarterlyDividend;
    private Double baseRateOfReturn;

    public Investment() {
        

    }

    public Investment(String code, String label, Double quarterlyDividend, Double baseRateOfReturn) {
        super(code, label);
        this.quarterlyDividend = quarterlyDividend;
        this.baseRateOfReturn = baseRateOfReturn;

    }

    public Double getQuarterlyDividend() {
        return quarterlyDividend;
    }

    public void setQuarterlyDividend(Double quarterlyDividend) {
        this.quarterlyDividend = quarterlyDividend;
    }

    public Double getBaseRateOfReturn() {
        return baseRateOfReturn;
    }

    public void setBaseRateOfReturn(Double baseRateOfReturn) {
        this.baseRateOfReturn = baseRateOfReturn;
    }

    public abstract Double riskMeasure();

    public abstract String accountType();

}
package pojo;



public abstract class Asset {
    private Integer assetId;
    private String code;
    private String label;
    
    public Asset() {
    }
    
    public Asset(String code, String label) {
        this.code = code;
        this.label = label;
    }

    public abstract Double riskMeasure();
    public abstract String accountType();
    
    public Integer getAssetId() {
        return assetId;
    }
    
    public void setAssetId(Integer assetId) {
        this.assetId = assetId;
    }
    
    protected String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }
}
Nov.04,2021

 protected String getCode() {
        return code;
    }
codegetpublic
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e86efa-e14.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e86efa-e14.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?