I am getting errors with starting JPA test. It is very huge stacktrace about "Syntax error in SQL statement", but previously I created my tables successfully, starting spring boot app.
I have my properties:
spring:
datasource:
url: ${dbUrl}
username: ${dbUsername}
password: ${dbPassword}
jpa:
hibernate:
ddl-auto: validate
properties:
hibernate:
jdbc:
lob:
non_contextual_creation: true
show-sql: true
flyway:
validate-on-migrate: false
enabled: true
My migration sql file:
CREATE SEQUENCE public.entity_id_sequence INCREMENT 1 START 1 MINVALUE 1;
CREATE TABLE IF NOT EXISTS movies
(
id BIGINT PRIMARY KEY,
title VARCHAR(30) UNIQUE NOT NULL
);
CREATE TABLE IF NOT EXISTS reservations
(...others
and my Test class:
@RunWith(SpringRunner.class)
@DataJpaTest
public class MovieEntityTest {
@Autowired
private MovieRepository movieRepository;
@Test
public void show_not_allow_null_title() {
Movie movie = new Movie();
movie.setTitle("My Title");
Movie inDB = movieRepository.save(movie);
assertThat(inDB.getTitle()).isNotNull();
}
}
last part of stacktrace is:
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "CREATE TABLE IF NOT EXISTS SCREENINGS
(
ID BIGINT PRIMARY KEY,
MOVIE_ID BIGINT REFERENCES MOVIES (ID) NOT NULL[*],
SCREENING_TIME TIMESTAMP NOT NULL,
ROOM_ID BIGINT REFERENCES SCREENING_ROOMS (ID) NOT NULL,
TICKET_PRICE NUMERIC(15, 2) NOT NULL
)"; expected "DEFERRABLE"; SQL statement:
CREATE TABLE IF NOT EXISTS screenings
(
id BIGINT PRIMARY KEY,
movie_id BIGINT REFERENCES movies (id) NOT NULL,
screening_time TIMESTAMP NOT NULL,
room_id BIGINT REFERENCES screening_rooms (id) NOT NULL,
ticket_price NUMERIC(15, 2) NOT NULL
) [42001-200]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:453)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:429)
at org.h2.message.DbException.getSyntaxError(DbException.java:243)
at org.h2.command.Parser.getSyntaxError(Parser.java:1053)
at org.h2.command.Parser.read(Parser.java:4987)
at org.h2.command.Parser.parseReferences(Parser.java:8315)
at org.h2.command.Parser.parseTableColumnDefinition(Parser.java:8530)
at org.h2.command.Parser.parseCreateTable(Parser.java:8379)
at org.h2.command.Parser.parseCreate(Parser.java:6276)
at org.h2.command.Parser.parsePrepared(Parser.java:903)
at org.h2.command.Parser.parse(Parser.java:843)
at org.h2.command.Parser.parse(Parser.java:819)
at org.h2.command.Parser.prepareCommand(Parser.java:738)
at org.h2.engine.Session.prepareLocal(Session.java:657)
at org.h2.engine.Session.prepareCommand(Session.java:595)
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1235)
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:212)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:201)
at org.flywaydb.core.internal.jdbc.JdbcTemplate.executeStatement(JdbcTemplate.java:244)
at org.flywaydb.core.internal.sqlscript.ParsedSqlStatement.execute(ParsedSqlStatement.java:111)
at org.flywaydb.core.internal.sqlscript.DefaultSqlScriptExecutor.executeStatement(DefaultSqlScriptExecutor.java:208)
... 66 more
How to fix that? I tried to disable flyway.enabled: false, tried to refresh connection to db, tried ddl-auto: create
Aucun commentaire:
Enregistrer un commentaire