0
0

More than 1 year has passed since last update.

org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "PERSON" not found; SQL statementエラー

Posted at

エラー内容。

image.png

resources/data.sqlにテストSQLを書いて
image.png

以下のテストコードを実行すると、テーブルを見つけられないエラーが発生してしまった。。。
image.png

エンティティクラスにEntityアノテーションを定義してあったのに、テーブルを参照できないとエラーが発生した。
image.png

それで色々調べてみたら、springboot2.5 versionがリリースによりある設定が必要になった。

Hibernate and data.sql
By default, data.sql scripts are now run before Hibernate is initialized. This aligns the behavior of basic script-based initialization with that of Flyway and Liquibase. If you want to use data.sql to populate a schema created by Hibernate, set spring.jpa.defer-datasource-initialization to true. While mixing database initialization technologies is not recommended, this will also allow you to use a schema.sql script to build upon a Hibernate-created schema before it’s populated via data.sql.

If you want to use data.sql to populate a schema created by Hibernate, set spring.jpa.defer-datasource-initialization to true

data.sqlを使って、Hibernateにより作成されたスキーマをpopulateするためには「spring.jpa.defer-datasource-initialization」をtrueに設定する必要があるとのこと!
以下のように、application.propertiesに設定しておけば、assertionエラーは出ているが先のテーブル参照エラーは解消したのがわかる!
image.png
image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0