Hibernates Schemaexport class is a great way to programmatically
populate a database with the current schema of your application. Of
course the class can't guess the database and other relevant options.
So a configuration is needed. With
org.hibernate.cfg.AnnotationConfiguration there is a class that
reads
in a hibernate.cfg.xml
and takes all needed properties from there. But
what to do when using JPA and there is only a persistence.xml?
AnnotationConfiguration won't take this xml file. Luckily
org.hibernate.ejb.Ejb3Configuration
will. See the following code:
Ejb3Configuration cfg = new
Ejb3Configuration();
cfg.configure("persistenceUnitName",
null);
SchemaExport export = new
SchemaExport(cfg.getHibernateConfiguration());
Note: This was done with Hibernate 3.5.6/JPA 2.0