-- auto-generated definition
create table company
(
id int auto_increment
primary key,
name varchar(255) null,
parent_id int null,
deleted tinyint(1) default 0 not null
);
-- auto-generated definition
create table company_detail
(
id int auto_increment
primary key,
address varchar(255) null,
company_id int null
);
create index idx_cid
on company_detail (company_id);
-- auto-generated definition
create table user
(
id int auto_increment
primary key,
name varchar(255) null,
balance int null,
version int null,
create_time datetime null,
update_time datetime null,
enabled tinyint(1) null,
deleted tinyint(1) null,
company_id int null,
constraint user_company_id_fk
foreign key (company_id) references company (id)
);
jdk版本:openjdk 11.0.19
参考代码如下
/**
/**
/**
/**
@OneToOne(mappedBy = "company") //一对一镜像端,必须可空 @Nullable CompanyDetail companyDetail();
@OneToMany(mappedBy = "company", orderedProps = { @OrderedProp(value = "id", desc = true) }) //一对多必须不可空 List users();
}
@Entity @Table(name = "company_detail") public interface CompanyDetail {
}
@Entity @Table(name = "user") public interface User {
}
-- auto-generated definition create table company_detail ( id int auto_increment primary key, address varchar(255) null, company_id int null );
create index idx_cid on company_detail (company_id);
-- auto-generated definition create table user ( id int auto_increment primary key, name varchar(255) null, balance int null, version int null, create_time datetime null, update_time datetime null, enabled tinyint(1) null, deleted tinyint(1) null, company_id int null, constraint user_company_id_fk foreign key (company_id) references company (id) );