hibernate反向生成数据库

用hibernate反向生成数据库的步骤为:

1.添加Hibernate jar包,写好hibernate.cfg.xml:

  
  
  
  
  
jdbc:mysql://localhost/test  
com.mysql.jdbc.Driver  
root  
root  
org.hibernate.dialect.MySQLDialect  
true  
  
  
  
  
  

2.编写实体类 Business.java:

package com.bc.bean;  
  
  
import java.util.Date;  
  
  
public class Business {  
private Integer uId;  
private String uName;  
private Date hirDate;  
private int zStoreNum;  
private int zBranchNum;  
private int zTradNum;  
private int sStoreNum;  
private int sBranchNum;  
private int sTradNum;  
private int bStoreNum;  
private int bBranchNum;  
private int bTradNum;  
private int totalNum;  
private String home;  
public Business() {  
super();  
}  
public Integer getuId() {  
return uId;  
}  
public void setuId(Integer uId) {  
this.uId = uId;  
}  
public String getuName() {  
return uName;  
}  
public void setuName(String uName) {  
this.uName = uName;  
}  
public Date getHirDate() {  
return hirDate;  
}  
public void setHirDate(Date hirDate) {  
this.hirDate = hirDate;  
}  
public int getzStoreNum() {  
return zStoreNum;  
}  
public void setzStoreNum(int zStoreNum) {  
this.zStoreNum = zStoreNum;  
}  
public int getzBranchNum() {  
return zBranchNum;  
}  
public void setzBranchNum(int zBranchNum) {  
this.zBranchNum = zBranchNum;  
}  
public int getzTradNum() {  
return zTradNum;  
}  
public void setzTradNum(int zTradNum) {  
this.zTradNum = zTradNum;  
}  
public int getsStoreNum() {  
return sStoreNum;  
}  
public void setsStoreNum(int sStoreNum) {  
this.sStoreNum = sStoreNum;  
}  
public int getsBranchNum() {  
return sBranchNum;  
}  
public void setsBranchNum(int sBranchNum) {  
this.sBranchNum = sBranchNum;  
}  
public int getsTradNum() {  
return sTradNum;  
}  
public void setsTradNum(int sTradNum) {  
this.sTradNum = sTradNum;  
}  
public int getbStoreNum() {  
return bStoreNum;  
}  
public void setbStoreNum(int bStoreNum) {  
this.bStoreNum = bStoreNum;  
}  
public int getbBranchNum() {  
return bBranchNum;  
}  
public void setbBranchNum(int bBranchNum) {  
this.bBranchNum = bBranchNum;  
}  
public int getbTradNum() {  
return bTradNum;  
}  
public void setbTradNum(int bTradNum) {  
this.bTradNum = bTradNum;  
}  
public int getTotalNum() {  
return totalNum;  
}  
public void setTotalNum(int totalNum) {  
this.totalNum = totalNum;  
}  
public String getHome() {  
return home;  
}  
public void setHome(String home) {  
this.home = home;  
}  
  
  
  
  
} 

3.编写实体类映射文件HomeBusiness.hbm.xml

  
  
  
  
   
              
              
              
           
     
     
     
     
     
     
     
     
     
  
  

4.Main执行创建 ExportDB.java:

package com.test.bean.test;  
  
  
import org.hibernate.cfg.Configuration;  
import org.hibernate.tool.hbm2ddl.SchemaExport;  
  
  
public class ExportDB {  
  
  
public static void main(String[] args) {  
//读取hibernate.cfg.xml文件  
Configuration cfg = new Configuration().configure();  
SchemaExport export = new SchemaExport(cfg);  
export.create(true, true);  
}  
} 

你可能感兴趣的:(hibernate反向生成数据库)