Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
DDL Generation, Hibernate 4+, Java 8, Reflections, Works with @Entities + different @typedef annotated package
import javax.persistence.Entity;
import javax.persistence.MappedSuperclass;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.hbm2ddl.Target;
import org.junit.Test;
import org.reflections.Reflections;
public class HibernateDDLGenerator {
public static final String ENTITIES_PACKAGE = "com.something";
public static final String ANNOTATED_PACKAGE = "com";
public static final String HBM_DIALECT = "org.hibernate.dialect.Oracle10gDialect";
public void ddl() throws Exception {
new SchemaExport(createHibernateConfig())
private Configuration createHibernateConfig() {
Configuration conf = new Configuration();
final Reflections reflections = new Reflections(ENTITIES_PACKAGE);
conf.addPackage(ANNOTATED_PACKAGE) // contains @TypeDefs
.setProperty(AvailableSettings.DIALECT, HBM_DIALECT);
return conf;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.