我有一个带有 id 属性的简单类,我想将其创建为 bigint。
这是属性
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@NotNull
public java.math.BigInteger id;
但是这是生成这个:
id decimal(19,2) not null auto_increment
我当然可以添加
@Column(columnDefinition = "bigint(20)")
然后它起作用了,但我不明白为什么 JPA 更喜欢匹配 decimal 而不是 bigint。
生成的映射还会导致无效 ID 错误,因为小数不是 auto_incrementable。
我正在使用具有 spring-boot-starter-data-jpa 依赖项的 spring boot。 配置如下:
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create
有什么想法吗?
最佳答案
JDBC 类型 BIGINT 表示介于 -9223372036854775808 和 9223372036854775807 之间的 64 位有符号整数值。 对应的 SQL 类型 BIGINT 是对 SQL 的非标准扩展。实际上,SQL BIGINT 类型目前尚未被任何主要数据库实现,我们建议应避免在可移植代码中使用它。
BIGINT 类型的推荐 Java 映射为 Java long。
关于java - JPA BigInteger 正在映射到 MySQL 的十进制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42692082/