[英]MyBatis mapping collection inside association
我有下一個 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>
實體類。
@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
在 db 層,路由具有 TmpCase 的外鍵:route.pid -> tmpCase.sid。
我認為這可能是我誤解了關聯塊內的工作收集塊與 columnPrefix 的關系。 我正在閱讀文檔,但沒有。 我會很高興得到任何幫助。
我找到了解決方案。 層次結構中的每個 class 必須具有正確工作的收集塊。 在我的情況下,頂級 class PreMigrationData 在數據庫中沒有 id。 我讓他們從子類中識別出來,這對我來說很好用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.