1

I was trying to create a table and in this I was using id attribute as UUID but it is showing error that it is not valid at this position it is expecting something else

CREATE TABLE  account (
a_id                    UUID                PRIMARY KEY,
a_hash                  VARCHAR(66)         NOT NULL,
a_email                 VARCHAR(500)        NOT NULL,
a_password              VARCHAR(60)         NOT NULL,
a_verification_key      UUID                NOT NULL,
a_disabled              BOOLEAN             DEFAULT FALSE NOT NULL,
a_verified              BOOLEAN             DEFAULT FALSE NOT NULL,
a_role                  VARCHAR(20)         NOT NULL,
a_created_at            TIMESTAMP           DEFAULT NOW() NOT NULL

);

Here a_id field is UUID type and a_verification_key is also UUID and it is giving me error in mysql workbench

Rajat Agrawal
  • 141
  • 1
  • 4
  • 13

1 Answers1

0

You can use UUID, specify columnDefinition to VARCHAR(255) or CHAR(16) or BINARY(16) using @Column, with this you can use the functionality of UUID. You may change strategy and generator as per your requirement

@Id
@GeneratedValue(generator = "uuid2")
@GenericGenerator(name = "uuid2", strategy = "org.hibernate.id.UUIDGenerator")
@Column(name = "a_id", columnDefinition = "VARCHAR(255)")
private UUID a_id;

Discussion Function UUID

Romil Patel
  • 12,879
  • 7
  • 47
  • 76