生成表结构的两种方式:
1,hbm2ddl.auto
2,使用SchemaExport工具类:Schema(表)
public void test() {
Configuration cfg = new Configuration().configure();
SchemaExport schema = new SchemaExport(cfg);
// 第一个参数script的作用: print the DDL to the console 是否在控制台上打印数据库语言
// 第二个参数export的作用 export the script to the database是否在数据库中执行脚本
schema.create(true, true);
schema.drop(true, true);
}这个工具类通过一个映射文件将数据库中的表建立出来了。即:在映射文件中对表的结构进行描述之后,用SchemaExport创建了表,同时也可以删除表。
注意:只能建表,不能建库