1

I want to have an infinitive primary key and that is 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

So I created my entity

public class Alarm {

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

And when I create the tables, I get the following error.

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'

So what have gone wrong here?

euraad
  • 2,467
  • 5
  • 30
  • 51

1 Answers1

6

BIGINT is the same as a Java Long, not a BigInteger.

The question even quoted that, so use Long, not BigInteger, which Hibernate seems to want to map to decimal(19,2), and that data type cannot be an auto-generated value.


UPDATE: As mentioned by dunni in a comment, you can force Hibernate to use the BIGINT data type with the @Column annotation:

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(columnDefinition = "BIGINT")
private BigInteger id;
Andreas
  • 154,647
  • 11
  • 152
  • 247
  • Ok. So MySQL can use BigInterger, but not Hibernate? – euraad Jan 10 '21 at 21:28
  • 2
    It can, but you need to tell Hibernate, that it must generate the column as BIGINT, not as DECIMAL, e.g. like mentioned here https://stackoverflow.com/questions/7081044/hibernate-how-to-set-sql-type-by-annotation – dunni Jan 10 '21 at 22:53