I have two classes where one inherits the other. I'm trying to map my resultSet to the subclass and Mybatis is ignoring the properties on the superclass (Setters also on the superclass)
Code is as below:
public class CocTreeNode extends CocBean implements TreeNode<CocTreeNode> {
private String level1, level2;
public void setLevel1(String level1){...}
public void setLevel2(String level2){...}
public String getLevel1(){...}
public String getLevel1(){...}
}
public class CocBean {
protected String name;
protected Double volume;
public void setName(String name){...}
public void setVolume(Double volume){...}
public String getName(){...}
public Double getVolume(){...}
}
My resultMap is -
<resultMap id="simpleRow" type="CocTreeNode">
<id property="level1" column="LEVEL1"/>
<id property="level2" column="LEVEL2"/>
<result property="name" column="NAME"/>
<result property="volume" column="VOLUME"/>
</resultMap>
The resulting CocTreeNode objects are populated with 'level1' and 'level2' attributes but not 'name' and 'volume'.
I have tried using extends but that didn't make any difference.
Any ideas will be appreciated.
The resultMap element is the most important and powerful element in MyBatis. It's what allows you to do away with 90% of the code that JDBC requires to retrieve data from ResultSet s, and in some cases allows you to do things that JDBC does not even support.
typeHandlers. Whenever MyBatis sets a parameter on a PreparedStatement or retrieves a value from a ResultSet, a TypeHandler is used to retrieve the value in a means appropriate to the Java type.
Unlike IBATIS, there is no <procedure> tag in MyBatis. To map the results of the procedures, we have created a resultmap named Student and to call the stored procedure named read_recordById. We have defined a select tag with id callById, and we use the same id in the application to call the procedure.
You have to use extends in your simpleRow resultmap to extend properties from CocBean's resultmap:
<resultMap id="CocBeanResult" type="CocBean">
<result property="name" column="NAME"/>
<result property="volume" column="VOLUME"/>
</resultMap>
<resultMap id="simpleRow" type="CocTreeNode" extends="CocBeanResult">
<result property="level1" column="LEVEL1"/>
<result property="level2" column="LEVEL2"/>
</resultMap>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With