gpt4 book ai didi

java - 将数据库模式保存在文件中使用 java?

转载 作者:行者123 更新时间:2023-11-30 11:44:29 24 4
gpt4 key购买 nike

您好,我需要将数据库架构保存在一个文件中。就像 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com