5

I started JPA 2.1 with Hibernate, and had the following lines in my persistence.xml

<property name="javax.persistence.schema-generation.scripts.action" value="drop-and-create"/>
<property name="javax.persistence.schema-generation.scripts.create-target" value="META-INF/sampleCreate.ddl"/>
<property name="javax.persistence.schema-generation.scripts.drop-target" value="META-INF/sampleDrop.ddl"/>

The tables are generated into my postgres DB.

However, there is no sampleCreate.dll in my META-INF folder, nor error.

What is missing here? Is it generated to other folder?

Thanks.

VHanded
  • 2,079
  • 4
  • 30
  • 55
  • persistence xml looks correct. I think issue is in path value. can you check adding / before META-INF like /META-INF/sampleCreate.ddl – Tanvi B Jun 27 '16 at 23:27
  • @TanviB still nothing appear. Is it suppose to generate the sampleCreate.ddl into my project folder or other folder? If I have , it can detect the import.sql properly. – VHanded Jun 28 '16 at 00:43
  • I have exact problem! it just not working, no generated scripts – miroque Apr 06 '17 at 06:22

2 Answers2

4

So, I've found solution, it's not full solution.

But still.

First of all, I'm using Wildfly 10.1.0

I struggled with the same problem, I didn't saw my generated sql files. But after some experiments I've found that, when Wildfly deploys my app, it generates sql files into it's bin directory (C:\wildfly\bin\).

But I wanted to see them in my project source folder.

For this you should use ABSOLUTE PATH. Like this below (and it had worked for me):

<property name="javax.persistence.schema-generation.scripts.action" value="drop-and-create"/>
<property name="javax.persistence.schema-generation.scripts.create-target" value="D:/myproject/src/resources/META-INF/sampleCreate.ddl"/>
<property name="javax.persistence.schema-generation.scripts.drop-target" value="D:/myproject/src/resources/META-INF/sampleDrop.ddl"/>

But this not convenient if you write code in command...

How it works with Glassfish, SpringBoot etc. I don't know, though I assume that like the same.

miroque
  • 320
  • 1
  • 5
  • 21
1

Based on my tests, the files are created relative to your CWD (current working directory).

You can see this by doing something like this to print or log the System.getProperty("user.dir") system property:

Getting the Current Working Directory in Java

I'm using maven, so if I do mvn test with a path of create.ddl my script gets created in the same directory I'm running maven from.

To find your current directory, either log or print the CWD and adjust your property values accordingly. You can also use relative paths, so if I wanted to put mine in the target/META-INF directory I would use ./target/META-INF/create.ddl since that is a valid directory relative to my CWD.

mikeb
  • 10,578
  • 7
  • 62
  • 120