【问题标题】:Spring boot application unable to execute insert statement from data.sql thrrows exception | table not foundSpring Boot 应用程序无法从 data.sql 执行插入语句引发异常 |找不到表
【发布时间】:2021-08-14 17:00:13
【问题描述】:

我正在尝试创建一个简单的 SpringDataJPA 应用程序。我正在使用 H2 数据库。在使用 @entity 注释对模型类进行注释后,表在 H2 DB 中成功创建,并且可以通过 h2-console 查看。但是,为了初始化表,我试图从 data.sql 插入值,但是在启动应用程序时,错误表明未找到该表。为什么我可以查看表格时找不到表格?

POM.xml

Model Class

application.properties

data.sql

Console output

【问题讨论】:

标签: java spring-boot hibernate spring-data-jpa h2


【解决方案1】:

Spring Boot 2.5.0 改变了 schema.sql 和 data.sql 的处理方式。

你必须设置

spring.jpa.defer-datasource-initialization=true

让您的示例工作。

请阅读https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto.data-initialization.using-basic-sql-scripts

【讨论】:

  • 非常感谢西蒙!!!! :) 我按照建议进行了更改,并且确实有效!!!耶耶耶
猜你喜欢
  • 2020-02-06
  • 1970-01-01
  • 2021-07-30
  • 2015-02-19
  • 2020-12-20
  • 2015-01-25
  • 2015-11-15
  • 2019-11-28
  • 2016-11-30
相关资源
最近更新 更多