当前位置:编程学习 > JAVA >>

hibernate 中常用到自动生成数据表代码

01
package opg;
02
 
03
import org.hibernate.cfg.Configuration;
04
import org.hibernate.tool.hbm2ddl.SchemaExport;
05
 
06
public class CreateTable {
07
 
08
    /**
09
     * @param args
10
     */
11
    public static void main(String[] args) {
12
        Configuration cfg=new Configuration().configure();
13
        SchemaExport se=new SchemaExport(cfg);
14
        se.create(true, true);
15
 
16
    }
17
 
18
}
注:

如果在 hibernate 自动生成表时,不删除现有的表 可以在hibernate 中配置:

1
<prop key="hibernate.hbm2ddl.auto">update</prop>

补充:软件开发 , Java ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,