@DarkByte2015

Почему возникает ошибка при создании структуры БД?

Есть приложение на spring и hibernate. В качестве СУБД используется H2 (тестовая БД которая нигде не хранит данные). При запуске ругается вот так:

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]


Причем много много раз на одну и ту же эту таблицу. :( Там при запуске просто выполняется 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)
);
  • Вопрос задан
  • 1824 просмотра
Решения вопроса 1
Ругается на точку с запятой
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
Bell Integrator Ульяновск
До 400 000 ₽
Bell Integrator Ижевск
До 400 000 ₽
Bell Integrator Хабаровск
До 400 000 ₽
29 мар. 2024, в 18:19
20000 руб./за проект
29 мар. 2024, в 18:08
2500 руб./за проект
29 мар. 2024, в 17:51
40000 руб./за проект