Here's my solution using Spring 4 and Hibernate 4. It doesn't respect some of the annotations on update like @ForeignKey, but it does on the export. There are a bunch of flags, and more classes, so there might be a better way still. I would love to do more of a workflow from this point. Perhaps some kind of workflow with git so you can track the changes and compare against your liquibase file?
public static void main(String[] args) throws IOException {
ApplicationContext context = new AnnotationConfigApplicationContext(DataConfig.class, PropertySourceConfig.class);
EntityManager entityManager = context.getBean(EntityManager.class);
DataConfig dataConfig = context.getBean(DataConfig.class);
String dialect = "org.hibernate.dialect.PostgreSQL9Dialect";
Configuration cfg = new Configuration();
cfg.setProperty("hibernate.hbm2ddl.auto", "update");
cfg.setProperty("hibernate.dialect", dialect);
cfg.setProperty("hibernate.connection.url", dataConfig.getUserNamePasswordConnectionUrl());
for (EntityType<?> entity : entityManager.getMetamodel().getEntities()) {
cfg.addAnnotatedClass(entity.getJavaType());
}
SchemaExport export = new SchemaExport(cfg);
export.setDelimiter(";");
File tempExportFile = File.createTempFile("Export", null);
export.setOutputFile(tempExportFile.getAbsolutePath());
export.setFormat(true);
export.execute(true, false, false, false);
System.out.println("EXPORT SCRIPT = " + FileUtils.readFileToString(tempExportFile));
File tempUpdateFile = File.createTempFile("Update", null);
SchemaUpdate update = new SchemaUpdate(cfg);
update.setDelimiter(";");
update.setOutputFile(tempUpdateFile.getAbsolutePath());
update.setFormat(true);
update.execute(true,false);
System.out.println("UPDATE SCRIPT = " + FileUtils.readFileToString(tempUpdateFile));
}