我有一个非常简单的脚本来为我的数据库生成DLL:
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似乎不适合我。我无法生成脚本。
发布于 2020-12-29 19:09:45
这一行:
EnumSet<TargetType> enumSet = EnumSet.of(TargetType.DATABASE);应更正如下:
EnumSet<TargetType> enumSet = EnumSet.of(TargetType.SCRIPT);https://stackoverflow.com/questions/65496085
复制相似问题