当配置好相关的文件,测试通过后,我们对数据库进行表的操作后,可以通过下面的代码在后台输出数据库脚本文件。
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配置文件的方式来自动生成数据库脚本的方法。通过创建并配置一个Configuration对象来加载hibernate.cfg.xml配置文件,然后使用SchemaExport类执行数据库脚本的创建。

被折叠的 条评论
为什么被折叠?



