Last active
September 10, 2021 14:14
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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