我正在尝试通过休眠5即时生成一些数据库/表模式:
StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder().applySetting("hibernate.hbm2ddl.auto", "create")
.applySetting("hibernate.dialect", "org.hibernate.dialect.MySQLDialect").applySetting("hibernate.id.new_generator_mappings", "true").build();
MetadataSources sources = new MetadataSources(standardRegistry);
for (Class clazz : classes) {
sources.addAnnotatedClass(clazz);
}
MetadataImplementor metadata = (MetadataImplementor)sources.getMetadataBuilder().build();
SchemaExport export = new SchemaExport();
export.create(EnumSet.of(TargetType.SCRIPT), sources.buildMetadata());
我感兴趣的是将结果输出到字符串中,而不是将其写入输出文件中。