Sergiu
Sergiu

Reputation: 2626

Hibernate5 - SchemaExport output the script in-memory as string instead to output file on disk

I'm trying to generate some database/table schemas on the fly, using hibernate 5 using something like this:

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());

What I'm interested in would be to output the results into a String instead of writing it to an output file.

Upvotes: 5

Views: 304

Answers (0)

Related Questions