How to generate SQL scripts at a specific location with JPA Tools and EclipseLink?

844 views Asked by At

I have a project set up with EclipseLink 2.7.0 and I'm using Dali in Eclipse. I am trying to use the context menu to generate SQL scripts but I'm having trouble getting the generated SQL scripts to be output at my desired location.

The persistence.xml file contains the following:

    <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
    <property name="eclipselink.application-location" value="src/main/resources/sql/postgresql/"/>
    <property name="eclipselink.create-ddl-jdbc-file-name" value="051-createDDL.sql"/>
    <property name="eclipselink.drop-ddl-jdbc-file-name" value="050-dropDDL.sql"/>

To have the SQL scripts generated, I right-click on the project, and select JPA Tools > Generate Tables from Entities… then I select Sql-script in the schema generation dialog that opens. Per this documentation, I was expecting the scripts to be made available under src/main/resources/sql/postgresql/ with the names I've specified but the files keep getting created at the root of the project under names dropDDL.sql and createDDL.sql. It's as if what I've specified in persistence.xml is ignored. I'm starting to wonder whether its contents is even used at all.

I have tried:

  • defining eclipselink.ddl-generation to all three allowed values (create-tables…), to no avail.
  • using the equivalent javax.persistence.schema-generation properties, also to no avail.

Is there a subtlety that I'm not aware of? Or some additional configuration? Maybe that I'm totally mistaken and the properties have nothing to do with Dali ?

1

There are 1 answers

1
Laird Nelson On

It is a complete mess, but here is what you need:

  • eclipselink.ddl-generation: This controls whether DDL generation happens at all.
  • eclipselink.ddl-generation.output-mode: This has to be set to either both or sql-script or no DDL will be written to any file anywhere.
  • eclipselink.application-location: This is set to the absolute path that will contain your DDL output files.
  • eclipselink.create-ddl-jdbc-filename: This is a path terminating in a filename that is relative to the absolute path supplied by the value of your eclipselink.application-location property. If you do not specify eclipselink.application-location, then this property is ignored.
  • eclipselink.drop-ddl-jdbc-filename: This is a path terminating in a filename that is relative to the absolute path supplied by the value of your eclipselink.application-location property. If you do not specify eclipselink.application-location, then this property is ignored.

In your example, you are missing eclipselink.ddl-generation.output-mode.