5.实体关系
www.suntodo.com
?
- Create a Student Entity

- Create a one to many relation


- Two-Way relation
If you wish to have a two-way relationship between the Entity.
* Check twoway checkbox

- Generate SQL Script
Click toolbar 
MySQL
create table Student (id bigint not null auto_increment, age integer, name varchar(255), teacher_id bigint, primary key (id));
create table Teacher (id bigint not null auto_increment, age integer, name varchar(255), primary key (id));
alter table Student add index FKF3371A1BDD2DCEF7 (teacher_id), add constraint FKF3371A1BDD2DCEF7 foreign key (teacher_id) references Teacher (id);
?
Oracle
create table Student (id number(19,0) not null, age number(10,0), name varchar2(255 char), teacher_id number(19,0), primary key (id));
create table Teacher (id number(19,0) not null, age number(10,0), name varchar2(255 char), primary key (id));
alter table Student add constraint FKF3371A1BDD2DCEF7 foreign key (teacher_id) references Teacher;
create sequence hibernate_sequence;
?
SQLServer
create table Student (id numeric(19,0) identity not null, age int null, name varchar(255) null, teacher_id numeric(19,0) null, primary key (id));
create table Teacher (id numeric(19,0) identity not null, age int null, name varchar(255) null, primary key (id));
alter table Student add constraint FKF3371A1BDD2DCEF7 foreign key (teacher_id) references Teacher;
- Create many-to-one Entity
- Create a User Entity

- Create a Organ Entity

- Create a many to one relation

- Generate SQL Script
Click toolbar 
MySQL
create table Organ (id bigint not null auto_increment, name varchar(255), primary key (id));
create table User (id bigint not null auto_increment, age integer, name varchar(255), organ_id bigint, primary key (id));
alter table User add index FK285FEB7C5567D7 (organ_id), add constraint FK285FEB7C5567D7 foreign key (organ_id) references Organ (id);
?
Oracle
create table Organ (id number(19,0) not null, name varchar2(255 char), primary key (id));
create table User (id number(19,0) not null, age number(10,0), name varchar2(255 char), organ_id number(19,0), primary key (id));
alter table User add constraint FK285FEB7C5567D7 foreign key (organ_id) references Organ;
create sequence hibernate_sequence;
?
SQLServer
create table Organ (id numeric(19,0) identity not null, name varchar(255) null, primary key (id));
create table User (id numeric(19,0) identity not null, age int null, name varchar(255) null, organ_id numeric(19,0) null, primary key (id));
alter table User add constraint FK285FEB7C5567D7 foreign key (organ_id) references Organ;
- Create many-to-many Entity
- Create a Customer Entity

- Create a Order Entity

- Create a many to many Relation

- Two-Way relation
If you wish to have a two-way relationship between the Entity.
* ManyToMany(Slave) Check twoway checkbox

- Generate SQL Script
Click toolbar 
MySQL
create table Customer (id bigint not null auto_increment, name varchar(255), primary key (id));
create table Customer_Order (customers_id bigint not null, orders_id bigint not null);
create table Order (id bigint not null auto_increment, name varchar(255), primary key (id));
alter table Customer_Order add index FK495F67AD236C2846 (customers_id), add constraint FK495F67AD236C2846 foreign key (customers_id) references Customer (id);
alter table Customer_Order add index FK495F67AD1695EBC0 (orders_id), add constraint FK495F67AD1695EBC0 foreign key (orders_id) references Order (id);
?
Oracle
create table Customer (id number(19,0) not null, name varchar2(255 char), primary key (id));
create table Customer_Order (customers_id number(19,0) not null, orders_id number(19,0) not null);
create table Order (id number(19,0) not null, name varchar2(255 char), primary key (id));
alter table Customer_Order add constraint FK495F67AD236C2846 foreign key (customers_id) references Customer;
alter table Customer_Order add constraint FK495F67AD1695EBC0 foreign key (orders_id) references Order;
create sequence hibernate_sequence;
?
SQLServer
create table Customer (id numeric(19,0) identity not null, name varchar(255) null, primary key (id));
create table Customer_Order (customers_id numeric(19,0) not null, orders_id numeric(19,0) not null);
create table Order (id numeric(19,0) identity not null, name varchar(255) null, primary key (id));
alter table Customer_Order add constraint FK495F67AD236C2846 foreign key (customers_id) references Customer;
alter table Customer_Order add constraint FK495F67AD1695EBC0 foreign key (orders_id) references Order;
?
- Create one-to-one Entity
- Create a Person Entity

- Create a Room Entity

- Create a one to one Relation


- Generate SQL Script
Click toolbar 
MySQL
create table Person (id bigint not null auto_increment, age integer, name varchar(255), room_id bigint, primary key (id));
create table Room (id bigint not null auto_increment, location varchar(255), primary key (id));
alter table Person add index FK8E488775CF9A987D (room_id), add constraint FK8E488775CF9A987D foreign key (room_id) references Room (id);
?
Oracle
create table Person (id number(19,0) not null, age number(10,0), name varchar2(255 char), room_id number(19,0), primary key (id));
create table Room (id number(19,0) not null, location varchar2(255 char), primary key (id));
alter table Person add constraint FK8E488775CF9A987D foreign key (room_id) references Room;
create sequence hibernate_sequence;
?
SQLServer
create table Person (id numeric(19,0) identity not null, age int null, name varchar(255) null, room_id numeric(19,0) null, primary key (id));
create table Room (id numeric(19,0) identity not null, location varchar(255) null, primary key (id));
alter table Person add constraint FK8E488775CF9A987D foreign key (room_id) references Room;
?