Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Schema export with hibernate annotations

I'm using hibernate annotations and i want to export my database schema.

Similar to the schemaexporttask with hbm xml files.

like image 208
Anthony Avatar asked Aug 03 '10 01:08

Anthony


1 Answers

You can. Just do it

AnnotationConfiguration configuration = new AnnotationConfiguration();

configuration
.addAnnotatedClass(<TYPE_YOUR_CLASS>.class)
.setProperty(Environment.USER, <TYPE_YOUR_USER>)
.setProperty(Environment.PASS, <TYPE_YOUR_PASSWORD>)
.setProperty(Environment.URL, <TYPE_YOUR_URL>)
.setProperty(Environment.DIALECT, <TYPE_YOUR_DIALECT>)
.setProperty(Environment.DRIVER, <TYPE_YOUR_DRIVER>);

SchemaExport schema = new SchemaExport(configuration);
schema.setOutputFile("schema.sql");

schema.create(<DO_YOU_WANT_TO_PRINT_TO_THE_CONSOLE>, <DO_YOU_WANT_TO_EXPORT_THE_SCRIPT_TO_THE_DATABASE>);
like image 146
Arthur Ronald Avatar answered Sep 20 '22 03:09

Arthur Ronald