触发报错SQL:
PREPARE stmt_mybatis(smallint, integer, varchar, varchar, varchar, integer, varchar, varchar, varchar, varchar, smallint, smallint, integer, varchar, varchar, integer)
AS INSERT INTO act_re_procdef_test(id_, rev_, category_, name_, key_, version_, deployment_id_, resource_name_, dgrm_resource_name_, description_, has_start_form_key_, has_graphical_notation_, suspension_state_, tenant_id_, engine_version_, app_version_)
VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16);
ERROR: column "has_start_form_key_" is of type boolean
but expression is of type smallint
HINT: You will need to rewrite or cast the expression.
规避方案测试 (两次cast转换,单次转换测试不通过)
PREPARE s5_full(smallint, integer, varchar, varchar, varchar, integer, varchar, varchar, varchar, varchar, smallint, smallint, integer, varchar, varchar, integer)
AS INSERT INTO act_re_procdef_test(id_, rev_, category_, name_, key_, version_, deployment_id_, resource_name_, dgrm_resource_name_, description_, has_start_form_key_, has_graphical_notation_, suspension_state_, tenant_id_, engine_version_, app_version_)
VALUES(
$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,
$11::text::bool, $12::text::bool,
$13,$14,$15,$16
);
方案2:
JDBC 在 setBoolean(n, true) 时发送 boolean OID(16),服务端 bool 列直接接受,无需 implicit cast。对应 MyBatis: 改 TypeHandler 让 Integer 字段走 boolean 序列化。
// 原 MyBatis 默认行为: Integer -> setInt -> OID 23
// 改为 TypeHandler: Integer -> setBoolean -> OID 16
// 模拟 setBoolean 的测试结果:
setBoolean(true) -> boolean OID(16) -> actual=True PASS
setBoolean(false) -> boolean OID(16) -> actual=False PASS
实现方式:注册自定义 TypeHandler,将 Integer/Short 字段映射为 prepareStatement.setBoolean。或直接改 Java 字段为 Boolean。
方案3:
通过 CREATE CAST 注册 integer/smallint → boolean 的 implicit cast。
CREATE CAST (smallint AS boolean) WITH FUNCTION int2_bool(smallint) AS IMPLICIT;
-- PanWeiDB 已内置 int2_bool() 函数:1→true, 0→false
建议首选方案一,方案二




