Here’s an easy snippet of code to perform this task. It output’s the “CREATE TABLE” adjust for the desired SQL dialect
public void entityToSQL() throws Exception{
Configuration cfg = new Configuration();
cfg.addAnnotatedClass(MyPOJO.class);
String[] lines = cfg.generateSchemaCreationScript(
new SQLServer2008Dialect());
for (String line : lines) {
System.out.println(line);
}
}
Advertisement