1

I have a Spring Boot application that has an embedded in-memory Derby DB and schema.sql is executed by Spring Boot at startup.

schema.sql:

create schema demo;
create table users (id varchar(10) primary key, name varchar(30), password varchar(30), mail varchar(100));
insert into users (id, name) values ('admin','admin');

I wanted to introduce spring-boot-devtools to automatically reload changes in my application, so I added the dependency to pom.xml.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
</dependency>

However, the above SQLs causes SQLExceptions and fails to reload because the schema and table has already exist.

So I tried to add the following SQLs, but if existsclause cannot be used in Derby.

drop schema if exists demo;
drop table if exists users;

Could anyone tell me the solution (alternative SQLs or how to ignore the SQL exceptions)?

Kohei TAMURA
  • 4,970
  • 7
  • 25
  • 49

2 Answers2

2

I can fix by adding the following property:

spring.datasource.continue-on-error=true

It can ignore SQLExceptions and reload changes in my application.

Kohei TAMURA
  • 4,970
  • 7
  • 25
  • 49
1

application.properties:

spring.datasource.username=app
spring.jpa.hibernate.ddl-auto=create-drop

see full worked example here: https://github.com/daggerok/spring-boot-derby-create-drop-example

output ot devtools reload:

...
2017-08-09 05:34:07.591  WARN 2728 --- [  restartedMain] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Warning Code: 10000, SQLState: 01J01
2017-08-09 05:34:07.592  WARN 2728 --- [  restartedMain] o.h.engine.jdbc.spi.SqlExceptionHelper   : Database 'memory:testdb' not created, connection made to existing database instead.
...
Maksim Kostromin
  • 3,273
  • 1
  • 32
  • 30