Mapping denormalized table to collection

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Mapping denormalized table to collection

Zanky
Hello everyone,
I'm trying to map some columns of a denormalized table as elements of
a collection.

I've built some example code:

Container class
---8<---
package net.zanky.example;

import java.util.List;

public class Register {

        private int eventCount;
        private int eventDuration;
        private List<RegisterEntry> register;

        public Register() {
        }

    // getter/setter removed

}
--->8---

Nested class:
---8<---
package net.zanky.example;

import java.util.Date;

public class RegisterEntry {

        private int index;
        private Date timestamp;
        private int duration;

        public RegisterEntry() {
        }

    // getter/setter removed

}
--->8---

mapper:
---8<---
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="net.zanky.example.RegisterMapper">

        <resultMap type="Register" id="registerMap">
                <result property="eventCount" column="event_count"/>
                <result property="eventDuration" column="event_duration"/>
                <collection property="register" javaType="List"
ofType="RegisterEntry">
                    <!-- ??? -->
                </collection>
        </resultMap>

        <select id="getQosInterruption" resultMap="qosInterruptionMap">
                SELECT
                    event_count,
                    event_duration,
                    event_0_timestamp,
                    event_0_duration,
                    event_1_timestamp,
                    event_1_duration,
                    event_2_timestamp,
                    event_2_duration,
                    event_3_timestamp,
                    event_3_duration,
                    event_4_timestamp,
                    event_4_duration
            FROM register
        </select>
</mapper>
--->8---

Any ideas on how to create the mapping?

Thank you, Andrea.