LoginSignup
3
6

More than 3 years have passed since last update.

Spring Boot+PostgreSQLのエラー解消方法

Posted at

現在、Springの勉強を行っているので、躓いた箇所等を備忘録として、ここに記載することにしました。

勉強教材

Spring徹底入門 Spring FrameworkによるJavaアプリケーション開発
※Spring Bootのバージョン1.3の為、そのままでは上手くいきません。

躓いた箇所:14章

対象ページ:p632~659
アプリ実行後、コンソールに以下のエラーが発生した。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource 
[org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: 
Invocation of init method failed; nested exception is javax.persistence.PersistenceException: 
[PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is 
org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table [meeting_room]

Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate 
SessionFactory; nested exception is org.hibernate.tool.schema.spi.SchemaManagementException: Schema-
validation: missing table [meeting_room]

Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: 
Schema-validation: missing table [meeting_room]

対処方法

下記2つのファイルの記述を追記して、エラーを解消することが出来た。

application.properties
spring.datasource.initialization-mode=always
spring.jpa.open-in-view=true

以前のバージョンでは、schema.sqlとdata.sqlをsrc/main/resources直下に置いておけば、アプリケーション起動時に実行されるようになっていたらしい。
新バージョンでは、spring.datasource.initialization-modeのデフォルトはembeddedとなっており、H2でなければ実行されない設定になっている。
そこで、alwaysにすることで何でもOKに設定することが出来る。

hibernate.properties
hibernate.jdbc.lob.non_contextual_creation=true

application.propertiesファイルと同じ場所に作成し、下記の行を記述する。

3
6
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
3
6