實體類欄位 mapperRule 對應 PG hstore 型別,直接 #{mapperRule} 插入報型別不符。
在 XML `
<insert id="insertImportMapper" parameterType="...ImportMapper">
insert into t_pm_sys_import_mapper
(uuid, mapper_name, matched_org_uuid, mapper_rule, creator_uuid, create_time, modify_time)
values
(#{uuid}, #{mapperName}, #{matchedOrgUuid}, #{mapperRule}::hstore, #{creatorUuid}, current_timestamp(0), current_timestamp(0))
</insert>
關鍵:#{mapperRule}::hstore 明確告訴 PG 將字串轉為 hstore。
String(JSON 字串)或 Map(需自定 TypeHandler 自動序列化)。Map,需實作 TypeHandler,在 setParameter 中用 ps.setObject(i, map, Types.OTHER) 並確保 PG JDBC 驅動支援 hstore(需在連線 URL 加 ?stringtype=unspecified 或呼叫 HStoreUtils.toString(map))。