I have a next resultMap
<resultMap id="resultMap" type="***.PreMigrationData"
autoMapping="true">
...
<association property="tmpCase" javaType="***.TmpCase" columnPrefix="i_">
<id column="sid" property="sid"/>
<result column="pid" property="pid"/>
<collection property="routes" ofType="***.Route"
resultMap="routes" columnPrefix="rt_"/>
</association>
</resultMap>
<resultMap id="routes" type="***.Route">
<result column="sid" property="sid"/>
<result column="pid" property="pid"/>
...
</resultMap>
Entities clases.
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class PreMigrationData{
...
private TmpCase tmpCase;
}
@Getter
@Setter
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class TmpCase {
private Long sid;
private Long pid;
...
private List<Route> routes;
}
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class Route {
private Long sid;
private Long pid;
}
SQL:
<select id="getCases" resultMap="resultMap">
<include refid="select"/>
WHERE ...
</select>
<sql id="select">
select
<include refid="case">
<property name="alias" value="pi"/>
<property name="prefix_source" value="i_"/>
</include>,
<include refid="rotue">
<property name="alias" value="pir"/>
<property name="prefix_source" value="i_rt_"/>
</include>
from tmp_case pi
LEFT JOIN route pir on pir.PID = pi.SID
In db layer, route have foreign key to TmpCase: route.pid -> tmpCase.sid.
I think it can be that i misunderstanding how work collection block inside association block with columnPrefix. I was reading documnetation, but nothing. I will be glad for any help.
I finded solution. Each of class in hierarchy must have for correctly work collection block. In my case top level class PreMigrationData haven't id in db. I let them id from subclass and it's work fine for me