Skip to content

Instantly share code, notes, and snippets.

@kauanmocelin
Last active September 10, 2021 14:14
Show Gist options
  • Save kauanmocelin/66e21fe040dbc52454bcb6c8fbd44525 to your computer and use it in GitHub Desktop.
Save kauanmocelin/66e21fe040dbc52454bcb6c8fbd44525 to your computer and use it in GitHub Desktop.
[Gerar esquema DDL de criação das entidades mapeadas no hibernate.cfg] #java #hibernate
AnnotationConfiguration hibernateConfiguration = new AnnotationConfiguration()
.configure("hibernate.cfg.xml");
Dialect dialect = (Dialect) Class.forName(hibernateConfiguration.getProperty("dialect")).newInstance();
String[] createStatements = hibernateConfiguration.generateSchemaCreationScript(dialect);
Stream<String> statements = Arrays.stream(createStatements);
try (FileOutputStream fos = new FileOutputStream("/home/kauan/sql-create-tables.ddl");
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(fos));) {
for (String sql : statements.collect(Collectors.toList())) {
out.write(sql);
out.newLine();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment