Recently I wanted to map some columns from a table to actual typed properties of an object, and some columns to a
public class Person {
private String firstName;
private String lastName;
private Map dynamicProperties;
// Getters and setters omitted.
}
and the following query:
select firstname, lastname, pref_1, pref_2, pref_3 from person;
The following resultmap maps the result of the query to the Person class:
<resultMap id="personDynamicProperties" type="map">
<result column="pref_1" property="pref_1"/>
<result column="pref_2" property="pref_2"/>
<result column="pref_3" property="pref_3"/>
</resultMap>
<resultMap id="personResult" type="Person">
<result column="firstname" property="firstName"/>
<result column="lastname" property="lastName"/>
<association property="dynamicProperties" resultMap="personDynamicProperties"/>
</resultMap>
No comments:
Post a Comment