I\'d like to use the Hibernate/HBM2DDL schema generation as a starting point for managing my application\'s SQL schema using a tool like Liquibase or Flyway. To assist with
After digging through the Hibernate Ant task's source on GitHub, I came up with the following solution:
/**
* Uses Hibernate's HBM2DDL {@link SchemaExport} utility to generate SQL
* database schemas.
*/
public final class HibernateSchemaPrinter {
/**
* A small application driver that calls
* {@link #printHibernateSchemaToStdout(String, Class)}.
*
* @param args
* (unused)
*/
public static void main(String[] args) {
printHibernateSchemaToStdout("gov.hhs.cms.bluebutton.data", PostgreSQL95Dialect.class);
}
/**
* Prints the Hibernate-/HDM2DDL- auto-generated SQL schema to
* {@link System#out}.
*
* @param persistenceUnitName
* the name of the JPA persistence unit to generate the schema
* for
* @param dialectType
* the Hibernate {@link Dialect} type to generate the schema for,
* e.g. {@link PostgreSQL95Dialect}
*/
public static void printHibernateSchemaToStdout(String persistenceUnitName, Class extends Dialect> dialectType) {
Map
Takes a bit more code these days, but still works, so good enough.