所以我有:
-
PK 列:
id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT
-
具有
id
字段的 POJO 实体java.math.BigInteger id field
-
映射器插入方法:
@Insert("INSERT INTO " + "table_name (" + "created_at_ts, " + "updated_at_ts" + ") " + "VALUES (" + "UNIX_TIMESTAMP(), " + "UNIX_TIMESTAMP()" + ")") @Options(useGeneratedKeys = true, keyColumn = "id") void insert(Entity entity);
-
对映射器插入方法的调用,如下所示:
commandMapper.insert(entity);
在成功插入一定数量的行之前,所有这些都可以正常工作。在子表中插入行时,我突然收到以下错误:
org.springframework.dao.DataIntegrityViolationException:
### Error updating database. Cause: java.sql.BatchUpdateException:
Out of range value for column 'parent_id' at row 1
看起来以下结果是可以的:
SELECT Auto_increment FROM information_schema.tables WHERE
table_name='table';
-> 32770
但是实体的 BigInteger id 字段的值是错误的:
System.out.println(entity.getId());
-> -32767
如何在实体 POJO 中得到负值?
显然地:
- 使用
BigIntegerTypeHandler
并不能解决问题 - 从
BIGINT UNSIGNED
切换到INT UNSIGNED
,从java.math.BigInteger
切换到Long
可以修复它。
但可能还有另一种方法?
非常感谢。
不得不碰到spring-jdbc和mariadb-java-client来解决这个问题。