因爲咱們每次編寫Hibernate的時候都須要寫實體,寫映射文件。並且Hibernate的映射文件也容易出錯。而逆向工程能夠幫咱們自動生成實體和映射文件,這樣就很是方便了。sql
在設計數據庫表時,咱們使用PowerDesigner來生成概念模型\物理模型…數據庫
設計一我的員組織架構:有機構、部門、員工、領導、角色、權限。markdown
最後生成物理模型是這樣子的:架構
咱們能夠單個生成,一個一個複製ide
也能夠把整個物理模型的sql語句一塊兒生成:idea
/*==============================================================*/ /* DBMS name: MySQL 5.0 */ /* Created on: 2017/6/5 20:22:52 */ /*==============================================================*/ drop table if exists person_role; drop table if exists t_company; drop table if exists t_dept; drop table if exists t_employee; drop table if exists t_person; drop table if exists t_privilege; drop table if exists t_role; drop table if exists t_role_privilege; /*==============================================================*/ /* Table: person_role */ /*==============================================================*/ create table person_role ( person_id varchar(32) not null, role_id varchar(32) not null, state varchar(32), primary key (person_id, role_id) ); /*==============================================================*/ /* Table: t_company */ /*==============================================================*/ create table t_company ( company_id varchar(32) not null, name varchar(32), primary key (company_id) ); /*==============================================================*/ /* Table: t_dept */ /*==============================================================*/ create table t_dept ( dept_id varchar(32) not null, company_id varchar(32) not null, name varchar(32), primary key (dept_id) ); /*==============================================================*/ /* Table: t_employee */ /*==============================================================*/ create table t_employee ( person_id varchar(32) not null, dept_id varchar(32), name varchar(32), employee_id varchar(32), primary key (person_id) ); /*==============================================================*/ /* Table: t_person */ /*==============================================================*/ create table t_person ( person_id varchar(32) not null, dept_id varchar(32) not null, name varchar(32), primary key (person_id) ); /*==============================================================*/ /* Table: t_privilege */ /*==============================================================*/ create table t_privilege ( privilege_id varchar(32) not null, name varchar(32), primary key (privilege_id) ); /*==============================================================*/ /* Table: t_role */ /*==============================================================*/ create table t_role ( role_id varchar(32) not null, name varchar(32), primary key (role_id) ); /*==============================================================*/ /* Table: t_role_privilege */ /*==============================================================*/ create table t_role_privilege ( role_id varchar(32) not null, privilege_id varchar(32) not null, primary key (role_id, privilege_id) ); alter table person_role add constraint FK_person_role foreign key (person_id) references t_person (person_id) on delete restrict on update restrict; alter table person_role add constraint FK_person_role2 foreign key (role_id) references t_role (role_id) on delete restrict on update restrict; alter table t_dept add constraint FK_companty_dept foreign key (company_id) references t_company (company_id) on delete restrict on update restrict; alter table t_employee add constraint FK_inherit foreign key (person_id) references t_person (person_id) on delete restrict on update restrict; alter table t_person add constraint FK_dept_person foreign key (dept_id) references t_dept (dept_id) on delete restrict on update restrict; alter table t_role_privilege add constraint FK_belong foreign key (role_id) references t_role (role_id) on delete restrict on update restrict; alter table t_role_privilege add constraint FK_own foreign key (privilege_id) references t_privilege (privilege_id) on delete restrict on update restrict;
在數據庫生成八張表:spa
參考博文!.net
值得注意的是:Intellij idea下生成出來的映射文件是沒有對應的關聯關係的。也就是說:一對多或多對多的關係,它是不會幫你自動生成的【好像是這樣子的】。。。所以,須要咱們本身添加Set【若是須要】設計