D
D
DarkByte20152017-07-27 13:34:22
Java
DarkByte2015, 2017-07-27 13:34:22

Why does an error occur when creating the database structure?

There is an application in spring and hibernate. H2 is used as a DBMS (a test database that does not store data anywhere). On startup it crashes like this:

13:21:09.943 4559 [main] WARN  o.s.b.c.e.AnnotationConfigEmbeddedWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceInitializer': Invocation of init method failed; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #3 of URL [file:/C:/Users/panov/Documents/Projects/backend/target/classes/schema.sql]: create table if not exists Counterparty ( id int primary key auto_increment, version int not null, legal_entity_id int not null foreign key references LegalEntity(id), person_id int not null foreign key references Person(id), bailee_id int not null foreign key references Person(id) ); nested exception is org.h2.jdbc.JdbcSQLException: Синтаксическая ошибка в выражении SQL "CREATE TABLE IF NOT EXISTS COUNTERPARTY ( ID INT PRIMARY KEY AUTO_INCREMENT, VERSION INT NOT NULL, LEGAL_ENTITY_ID INT NOT NULL FOREIGN[*] KEY REFERENCES LEGALENTITY(ID), PERSON_ID INT NOT NULL FOREIGN KEY REFERENCES PERSON(ID), BAILEE_ID INT NOT NULL FOREIGN KEY REFERENCES PERSON(ID) ) "; ожидалось "AS, DEFAULT, GENERATED, NOT, NULL, AUTO_INCREMENT, BIGSERIAL, SERIAL, IDENTITY, NULL_TO_DEFAULT, SEQUENCE, SELECTIVITY, COMMENT, CONSTRAINT, PRIMARY, UNIQUE, NOT, NULL, CHECK, REFERENCES, ,, )"
Syntax error in SQL statement "CREATE TABLE IF NOT EXISTS COUNTERPARTY ( ID INT PRIMARY KEY AUTO_INCREMENT, VERSION INT NOT NULL, LEGAL_ENTITY_ID INT NOT NULL FOREIGN[*] KEY REFERENCES LEGALENTITY(ID), PERSON_ID INT NOT NULL FOREIGN KEY REFERENCES PERSON(ID), BAILEE_ID INT NOT NULL FOREIGN KEY REFERENCES PERSON(ID) ) "; expected "AS, DEFAULT, GENERATED, NOT, NULL, AUTO_INCREMENT, BIGSERIAL, SERIAL, IDENTITY, NULL_TO_DEFAULT, SEQUENCE, SELECTIVITY, COMMENT, CONSTRAINT, PRIMARY, UNIQUE, NOT, NULL, CHECK, REFERENCES, ,, )"; SQL statement:
create table if not exists Counterparty ( id int primary key auto_increment, version int not null, legal_entity_id int not null foreign key references LegalEntity(id), person_id int not null foreign key references Person(id), bailee_id int not null foreign key references Person(id) ) [42001-193]

And many many times on the same table. :( There, at startup, the SQL script is simply executed, which creates the database structure. That’s what it swears at. I don’t understand what the problem is, because the script is correct in my opinion. Here it is (specifically for this table):
create table if not exists Counterparty (
  id int primary key auto_increment,
  version int not null,
  legal_entity_id int not null foreign key references LegalEntity(id),
  person_id int not null foreign key references Person(id),
  bailee_id int not null foreign key references Person(id)
);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan Lopatin, 2017-07-27
@DarkByte2015

Swears at a semicolon

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question