Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Comments on SQL scripts referenced in persistence configuration must have each statement on its own line

Post

SQL scripts referenced in persistence configuration must have each statement on its own line

+2
−0

I'm currently working on a Java application using Jakarta Persistence with EclipseLink and PostgreSQL. While setting up the application to test the database layer, the persistence configuration is done in such way to automatically create and initialize the database:

<?xml version="1.0" encoding="UTF-8"?>
<persistence ...>
  <persistence-unit name="test">
    <properties>
      ...
      <property name="jakarta.persistence.schema-generation.create-script-source" value="database/schema.sql" />
      <property name="jakarta.persistence.schema-generation.database.action" value="create" />
      <property name="jakarta.persistence.sql-load-script-source" value="database/data.sql" />
      ...
    </properties>
  </persistence-unit>
</persistence>

<!-- $projectRoot/src/main/resources/META-INF/persistence.xml -->

The problem I'm facing is with both, schema.sql and data.sql scripts. There seems to be a formatting issue where every SQL statement must be on its own line for the scripts to be executed correctly — othewise they aren't executed. This has never been an issue with other tools I've used in the past, such as Liquibase and Flyway.

This is an example of the content that's found on both SQL scripts:

create table table_name_one (id uuid not null, ..., primary key (id));

create table table_name_two (id uuid not null, ..., primary key (id));

-- $projectRoot/src/main/resources/database/schema.sql
insert into table_name_one (id, ...) values (...);
insert into table_name_one (id, ...) values (...);

insert into table_name_two (id, ...) values (...);
insert into table_name_two (id, ...) values (...);

-- $projectRoot/src/test/resources/database/data.sql

Anyway, after finding the issue, I thought it was the JPA provider or the database, so I changed them (just to verify) to Hibernate and MySQL...but regardless, I noticed the exact same issue.

Is there a way to configure JPA to allow multi-line SQL statements in the SQL scripts?

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

Script delimeter (2 comments)
Script delimeter
talex‭ wrote 25 days ago

Just to make sure. You have ; at end of each SQL statement in your scripts?

ɯıpɐʌ‭ wrote 25 days ago

Indeed. I'll update the question to make this clear — I forgot to mention it and it's an important point.