Allow schema-export commands written to file to truncate in addition to current appending

Description

I am using JPA (hibernate implementation) with spring in a project. When running automated test the persistance.xml is configured through spring to generate the create and drop scripts for the database.

There is only one entity called Book. That should create one line in the create script to create the table Book and one line in the drop script to drop the table Book.

The problem is that everytime i run the tests the scripts are not regenerated but instead a new line is added to the script. So if i run the test 3 times the script looks like:

create table Book (title varchar(255) not null, primary key (title))
create table Book (title varchar(255) not null, primary key (title))
create table Book (title varchar(255) not null, primary key (title))

When i switch back to the previous version i was using 4.3.6 everything works fine.

Environment

None

Activity

Show:
Steve Ebersole
June 14, 2017, 7:23 PM

Want to take a look at fitting this into your 6.0 schema tooling work?

Andrea Boriero
June 15, 2017, 7:38 AM

do u think it is better to add a new config property for this behaviour or just to change the actual behaviour to always recreate the file?

Steve Ebersole
June 15, 2017, 12:30 PM

I'm thinking a config property would be best

Javier Peña
June 15, 2017, 4:54 PM

First of all thanks for the quick response.

And i do not mean to interfere but i thought i would be good if i let you bare in mind a couple of points

I am using the JPA porperties. I was under the impresion that those should have the same behaviour regardless the implementation of JPA.

The configuration i have is pure JPA:
javax.persistence.schema-generation.scripts.action = drop-and-create
javax.persistence.schema-generation.scripts.drop-targe = some/folder/drop.sql
javax.persistence.schema-generation.scripts.create-target = some/folder/create.sql

In version 4.3.6 this configuration would truncate the files. Thus i would expect that this would be the same behaviour in later versions and adding the option to append instead of truncate should be the additional configuration. At least that would be my understanding, although you know this a lot better than me.

Steve Ebersole
June 16, 2017, 2:48 AM

If you are going to throw "JPA compliance" around, of course you are going to be expected to list the section in the JPA spec that says that. I'll save you the time... there is none, JPA is silent on this. And previously Hibernate did not document either behavior specifically. Meaning it was completely undefined.

Appending is clearly the safest option. Given appending, over-writing can still be achieved by truncating the file before you start. Hence appending should be the default.

Assignee

Andrea Boriero

Reporter

Javier Peña

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Major
Configure