如何在Grials GORM中使用自定义主键,我有以下域类: -
class People {
static mapping = {
version false
}
String people_id;
String name;
String apppassword;
String card;
String role;
boolean visible;
String phone;
byte[] image;
Date creationTime;
Date modificationTime;
static constraints = {
id name: 'people_id', type: 'string'
people_id(nullable: false )
name(nullable: false)
apppassword(nullable: true)
card(nullable: false)
role(nullable: false)
visible(nullable: true)
phone(nullable: true)
image(nullable: true)
creationTime(nullable: true)
modificationTime(nullable: true)
}
}
当我在日志下面运行服务器控制台打印时(它显示id
作为主键但我希望people_id
作为主键): -
Hibernate: create table people (id bigint not null auto_increment, apppassword varchar(255), card varchar(255) not null, creation_time datetime, image tinyblob, modification_time datetime, name varchar(255) not null, people_id varchar(255) not null, phone varchar(255), role varchar(255) not null, visible bit not null, primary key (id)) ENGINE=InnoDB
在MySql中,我的DML是: -
CREATE TABLE PEOPLE (
PEOPLE_ID VARCHAR(255) NOT NULL,
NAME VARCHAR(255) NOT NULL,
APPPASSWORD VARCHAR(255),
CARD VARCHAR(255),
ROLE VARCHAR(255),
VISIBLE BIT DEFAULT b'1' NOT NULL,
PHONE VARCHAR(255),
IMAGE MEDIUMBLOB,
CREATION_TIME DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
MODIFICATION_TIME DATETIME ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (PEOPLE_ID)
)
我已经关注了这个link,但看起来这个解决方案对我不起作用。 请帮忙