从eclipse链接JPA实体创建数据库表



我想将我的Java应用程序部署到Heroku,我使用eclipse链接JPA。

要做到这一点,我需要通过Java创建表,到目前为止,我已经得到了下面的代码,但是我如何让DDL创建一个表。我将在MySQL上运行应用程序进行开发,Heroku是用于生产的Postgres。因此,我希望create table语句考虑到这一点。
import javax.persistence.*;
public class SchemaCreator
{
  public static void main(String[] args)
  {
    EntityManagerFactory factory =
    Persistence.createEntityManagerFactory("bitcoin");
    EntityManager em = factory.createEntityManager();
    String ddl = /// <--- How do I get it ?
    em.createNativeQuery(ddl);
  }
}

好了,我明白了。

如果我将以下条目添加到persistence.xml

<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="database"/> 

当我第一次访问一个实体时,如果它还没有在数据库中,一个表将被创建。

最新更新