您好,我需要将数据库架构保存在一个文件中。就像 Hibernate 在其 hbm 文件中做的那样(保存表名、列名和类型以及主外键)是否有一种模式可以做到这一点?
最佳答案
您可以使用 Hibernate 类 org.hibernate.tool.hbm2ddl.SchemaExport
您可以将您的 Hibernate 配置传递给它,然后使用方法 execute()打印模式。
这是一个代码示例:
Configuration cfg = new Configuration();
cfg.addResource(mappingFile); // mapping to your hibernate mapping xml
cfg.setProperties(props); // hibernate configuration properties, like dialect, connection url, etc.
SchemaExport schemaExport = new SchemaExport(cfg);
schemaExport.setDelimiter(";");
schemaExport.setOutputFile("database-script.sql");
schemaExport.setFormat(true);
schemaExport.execute(false, false, false, true);
关于java - 将数据库模式保存在文件中使用 java?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10776817/