Generate DDL for JPA 2.0 with EclipseLink

我的梦境 提交于 2019-12-01 15:08:54
Edwin Dalorzo

You can find your answers in the EclipseLink Documentation, more specifically in the section called Using EclipseLink JPA Extensions for Schema Generation.

There you will find that there is a property called eclipselink.ddl-generation with possible values like NONE | CREATE_ONLY | DROP_AND_CREATE.

There you will find an additional property named eclipselink.ddl-generation.output-mode, whose documentation is in this same page.

It will provide you control on whether you want just to generate a script or actually execute the DDL against the database.

I hope that helps!

I know this is a little late but I have been struggling with the same problem. What I found was after doing the configurations like setting the "eclipselink.ddl-generation", then I hooked the following code into our build I got ddl file to generate. EntityManagerHolder class would have to be defined in your context.xml. It is a bit hackish but works.

public class EntityManagerHolder {
  @PersistenceContext(type = PersistenceContextType.TRANSACTION)
  private EntityManager entityManager;
  protected EntityManager getEntityManager() {
    return entityManager;
  }
}

public class SQLGeneration {
  public static void generateSQLFiles() {
ClassPathXmlApplicationContext application_context = new ClassPathXmlApplicationContext(
    "META-INF" + File.separator + "spring" + File.separator
        + "context.xml");
EntityManagerHolder entity_manager_holder = (EntityManagerHolder) application_context
    .getBean("entityManagerHolder");
entity_manager_holder.getEntityManager().getEntityManagerFactory()
    .createEntityManager();
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!