1

我想要一个不定式主键,那就是BigInteger. https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-type-conversions.html

BIGINT[(M)] [UNSIGNED]  BIGINT [UNSIGNED]   java.lang.Long, if UNSIGNED java.math.BigInteger

所以我创建了我的entity

public class Alarm {

    // ID
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private BigInteger id;

当我创建表时,出现以下错误。

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table alarm (id decimal(19,2) not null auto_increment, frequencyp0p1p2 integer not null, frequencyp3p7p8 integer not null, frequencyp4 integer not null, frequencyp6p5 integer not null, port_description varchar(255), primary key (id)) engine=MyISAM" via JDBC Statement

Caused by: java.sql.SQLSyntaxErrorException: Incorrect column specifier for column 'id'

那么这里出了什么问题呢?

4

1 回答 1

5

BIGINT与 Java 相同Long,而不是BigInteger.

该问题甚至引用了这样的话,所以使用Long, not BigInteger,Hibernate 似乎想要映射到decimal(19,2),并且该数据类型不能是自动生成的值。


更新:正如 dunni 在评论中提到的,您可以强制 Hibernate 使用BIGINT带有注释的数据类型@Column

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(columnDefinition = "BIGINT")
private BigInteger id;
于 2021-01-10T21:23:07.380 回答