【发布时间】:2017-07-30 05:53:46
【问题描述】:
我有一个带有 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 更喜欢匹配十进制而不是 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
有什么想法吗?
【问题讨论】:
-
AUTO_INCREMENT 仅适用于整数和浮点类型。请参阅 MySQL 手册,创建表。 AUTO_INCREMENT 不适用于 DECIMAL
-
是的,我知道这一点。问题更多是关于为什么 jpa 映射 BigInteger 类型的小数?
标签: java mysql jpa spring-boot