Persistence.generateSchema - the output file contains duplicated DDL statements

Description

Hi,

I am using the JPA2.1 API: Persistence.generateSchema(persistentUnit, properties) with Hibernate 4.3,5.0,5.1.

My code: https://github.com/lorislab/jpa2-maven-plugin/blob/master/src/main/java/org/lorislab/maven/jpa2/SchemaGeneratorMojo.java

Hibernate 4.3.x, 5.0.x generated the DDL-script fine (without semicolon).
Hibernate 5.1 and Persistence.generateSchema generated the DDL-script with semicolon but the output file contains two same DDL-scripts.
Example:
Create Table TABLE1
Create Index INDEX1
Create Table TABLE1
Create Index INDEX1

I think it’s because of the code in the EntityManagerFactoryBuilderImpl and SessionFactoryImpl.

Class: org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.generateSchema

try {
SessionFactoryBuilder sfBuilder = metadata().getSessionFactoryBuilder();
populate( sfBuilder, standardServiceRegistry );
sfBuilder.build();

SchemaManagementToolCoordinator.process(
metadata, standardServiceRegistry, configurationValues, DelayedDropRegistryNotAvailableImpl.INSTANCE
);
}

The line sfBuilder.build(); call the org.hibernate.internal.SessionFactoryImpl constructor.
Line 458 of the SessionFactoryImpl constructor:

SchemaManagementToolCoordinator.process(
metadata,
serviceRegistry,
properties,
new DelayedDropRegistry() {
@Override
public void registerOnCloseAction(DelayedDropAction action) {
SessionFactoryImpl.this.delayedDropAction = action;
}
}
);

Commit: https://github.com/hibernate/hibernate-orm/commit/17de173cb5334d866f1886d3e057f49a6c987bad

Attachments

1

Activity

Show:

Andrea Boriero March 25, 2016 at 12:02 PM

Andrea Boriero March 24, 2016 at 12:50 PM

Hi ,

thanks for the test case.
I'll give a look at it.

Best,

Andrea

Andrej Petras March 24, 2016 at 12:42 PM

Hi Andrea,

Thank you for checking this ticket.

I created a simple example for this issue.
The test uses the Persistence.generateSchema method to generate the schema and check the repeated lines in the target/create.sql file.

The create.sql files should have only one table for one entity but it contains two same tables .

Cheers,
Andrej

Andrea Boriero March 23, 2016 at 7:57 PM

Hi ,

I noticed the problem occurs when you execute more than once the schema generation without deleting the output script file.

Fixed

Details

Assignee

Reporter

Labels

Components

Fix versions

Affects versions

Priority

Created March 7, 2016 at 11:18 PM
Updated June 2, 2016 at 3:51 AM
Resolved May 12, 2016 at 7:53 AM