首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用SchemaExport生成脚本文件

无法使用SchemaExport生成脚本文件
EN

Stack Overflow用户
提问于 2020-12-29 17:19:25
回答 1查看 28关注 0票数 1

我有一个非常简单的脚本来为我的数据库生成DLL:

代码语言:javascript
复制
public static void main(String[] args) {
    
   Map<String, String> settings = new HashMap<>();
   settings.put("connection.driver_class", "com.mysql.jdbc.Driver");
   settings.put("dialect", "org.hibernate.dialect.MySQLDialect");
   settings.put("hibernate.connection.url", "jdbc:mysql://localhost:3306/mydatabase");
   settings.put("hibernate.connection.username", "root");
   settings.put("hibernate.connection.password", "root");
   settings.put("hibernate.show_sql", "true");
   settings.put("hibernate.format_sql", "true");
    
   ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
       .applySettings(settings)
       .build();
   MetadataSources metadata = new MetadataSources(serviceRegistry);
   metadata.addAnnotatedClass(AddressEntity.class);
   metadata.addAnnotatedClass(CompanyEntity.class);
    
   EnumSet<TargetType> enumSet = EnumSet.of(TargetType.DATABASE);
   SchemaExport schemaExport = new SchemaExport();
   schemaExport.setOutputFile("myScript.sql");
   schemaExport.execute(enumSet, SchemaExport.Action.BOTH, metadata.buildMetadata());
}

如果我查看调试和信息信息,它是工作的。我可以看到DLL语句正在打印出来。

我唯一的问题是将它导出到文件中。我什么都试过了,但setOutputFile似乎不适合我。我无法生成脚本。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-29 19:09:45

这一行:

代码语言:javascript
复制
EnumSet<TargetType> enumSet = EnumSet.of(TargetType.DATABASE);

应更正如下:

代码语言:javascript
复制
EnumSet<TargetType> enumSet = EnumSet.of(TargetType.SCRIPT);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65496085

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档