【发布时间】:2017-12-24 08:26:31
【问题描述】:
在迁移到 postgresql 时,我面临以下问题
键列 veh_reg_authority 和 id 的类型不兼容:numeric 和 bigint。
以下是映射:
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "VEH_REG_AUTHORITY", columnDefinition ="Numeric(12,0)")
private VehicleRegistrationAuthority vehicleRegistrationAuthority;
VehicleRegistrationAuthority 具有 id 类型的 Long,因此根据 PostgreSQL 转换为 BIGINT。
所以一个简单的解决方案是相应地更改 columnDefinition ="Numeric(12,0)",但我们不能这样做,因为它适用于 oracle 和 mysql,并且它在 out 代码中被大量使用,因此不可能改变。
以下是 Oracle、Mysql 和 PostgreSQL 中的类型:
column java type Oracle Mysql PostgreSQL
id Long NUMBER BIGINT BIGINT
veh_reg_authority VehicleRegistrationAuthority NUMBER decimal(12,0) NUMERIC
创建外键休眠时会出现以下问题。
Caused by: org.postgresql.util.PSQLException: ERROR: foreign key constraint "fk7gyqskn6x2l2910xhhtjgvh0j" cannot be implemented
Detail: Key columns "veh_reg_authority" and "id" are of incompatible types: numeric and bigint.
【问题讨论】:
标签: sql oracle postgresql hibernate jpa