【问题标题】:Spring-boot doesn't create tables in h2 - JPA/HibernateSpring-boot 不在 h2 中创建表 - JPA/Hibernate
【发布时间】:2019-06-12 19:13:00
【问题描述】:

我已尝试按照本指南使用 Spring Boot 将我的数据存储在 h2 数据库中。 https://memorynotfound.com/spring-boot-spring-data-jpa-hibernate-h2-web-console

但似乎没有创建数据库表。它也没有收到错误消息,所以我不知道我做错了什么。

我尝试添加@EntityScan,但它不起作用。

*更新

spring.h2.console.enabled=true
spring.h2.console.path=/console
spring.h2.console.settings.trace=false
spring.h2.console.settings.web-allow-others=false

spring.datasource.url=jdbc:h2:mem:example-app;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.platform=h2
spring.datasource.username = sa
spring.datasource.password =
spring.datasource.driverClassName = org.h2.Driver
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect

spring.jpa.hibernate.ddl-auto = update
spring.jpa.properties.hibernate.show_sql=false
spring.jpa.properties.hibernate.use_sql_comments=false
spring.jpa.properties.hibernate.format_sql=false

【问题讨论】:

  • ddl-auto: drop-create
  • 显示相关配置。
  • 请出示您的 application.properties 文件
  • 你怎么知道没有创建表?您是否尝试过使用 h2 控制台?如果是,请拍下您如何使用它的照片(或连接信息)?
  • 已解决。 @ThiagoChagas 让我走上了正确的道路。我的网址有误。

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


【解决方案1】:

确保你有这个配置属性(虽然它自动像 h2 那样):

spring:
  jpa:
    hibernate:
      ddl-auto: update

【讨论】:

    猜你喜欢
    • 2021-09-15
    • 2017-08-11
    • 2021-08-12
    • 2016-10-29
    • 2020-02-29
    • 2021-02-09
    • 2018-05-11
    • 2019-03-05
    相关资源
    最近更新 更多