I want to deploy my Java application to Heroku, I'm using eclipse link JPA.
To do that I need to create the tables via a Java, so far I've got the code below but how do I get the DDL to create a table. I'll be running the app on MySQL for development and Heroku is Postgres for production. Therefore, I'd like the create table statement to take this into account.
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);
}
}
Right-click the JPA project in the Project Explorer and select JPA Tools > Generate Entities from Tables. On the Select Tables page of the Generate Entities from Tables wizard, select your database connection and schema. To create a new database connection, click Add connection.
EclipseLink Native Object Relational Mapping (ORM) provides an extensible object-relational mapping framework. It provides high-performance object persistence with extended capabilities configured declaratively through XML.
Eclipse Persistence Services Project (EclipseLink) is a comprehensive persistence framework delivering a set of persistence services based around leading standards with advanced extensions. Consumers can use EclipseLink within Java EE, SE, and OSGi/Equinox environments.
OK, I figured it out.
If I add the following entried to my persistence.xml
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="database"/>
Then when I first access an entity if it's not already in the dataabse a table will be created.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With