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.

Post History

66%
+2 −0
Q&A SQL scripts referenced in persistence configuration must have each statement on its own line

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 ...

0 answers  ·  posted 25d ago by ɯıpɐʌ‭  ·  edited 25d ago by ɯıpɐʌ‭

#2: Post edited by user avatar ɯıpɐʌ‭ · 2024-09-23T14:25:52Z (25 days ago)
Udate the question to include examples of SQL scripts
  • 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
  • <?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`.
  • 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?
  • 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
  • <?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:
  • ```sql
  • 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
  • ```
  • ```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?
#1: Initial revision by user avatar ɯıpɐʌ‭ · 2024-09-22T21:50:44Z (25 days ago)
SQL scripts referenced in persistence configuration must have each statement on its own line
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
<?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`.

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?