您的位置:首页 > 其它

Hibernate根据配置文件生成表结构和创建表的脚本

2016-04-16 00:18 435 查看
// 根据配置生成表结构
@Test
public void test() throws Exception {
Configuration cfg = new Configuration().configure();
SchemaExport schemaExport = new SchemaExport(cfg);
// 第一个参数script的作用: print the DDL to the console
// 第二个参数export的作用: export the script to the database
schemaExport.create(true, true);
}


第一个参数的作用是判断是否将DDL即建表等语句打印到控制台

第二个参数的作用是判断是否执行对应的DDL语句

此外除了这种方式,也可以用配置文件 的方式来生成表结构

<property name="hbm2ddl.auto">update</property>

<property name="hbm2ddl.auto">create</property>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  hibernate