【发布时间】:2020-10-02 19:58:28
【问题描述】:
我一直在查看 Stack Overflow 和论坛,但到目前为止还没有运气。我有一个 Spring Boot 2.3.3.RELEASE、JPA/Hibernate 堆栈。
我有一张桌子
CREATE TABLE table_name (...)
我创建了不带引号的小写表格。它在本地运行良好。在本地,我在带有 Amazon Corretto jdk11.0.8_10 的 Windows 环境中。
现在我已经创建了一个 AWS RDS PostreSQL 数据库实例。它托管在 Linux 上。 当我从 Windows 连接到数据库时,它工作正常。但是当我在 AWS Elastic Beanstalk 上部署我的应用程序时,当 Hibernate 尝试查询数据库时,我遇到了错误
org.postgresql.util.PSQLException: ERROR: relation "table_name" does not exist.
我的实体看起来像
@Entity
@Table(name = "table_name")
public class User {
}
该表在默认的public 架构中。
我的application.properties:
spring.datasource.url=jdbc:postgresql://${RDS_HOSTNAME}:${RDS_PORT}/${RDS_DB_NAME}
spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.username=${RDS_USERNAME}
spring.datasource.password=${RDS_PASSWORD}
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL10Dialect
spring.jpa.properties.hibernate.globally_quoted_identifiers=false
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=none
spring.jpa.hibernate.default_schema=public
我是否将架构放在@Table 中都没有关系。
我能发现的唯一区别是环境。 Windows 与 Linux。当我在本地启动应用程序并使用 AWS RDS DB 时,它可以工作。
【问题讨论】:
-
你可以试试
spring.jpa.properties.hibernate.default_schema=public吗? -
嗨,这是我帖子中 application.properties 的最后一行 ;)
-
不,不一样,顺便说一句,将您的
spring.jpa.hibernate.ddl-auto=none更改为create或update(如果有数据,请备份您的数据库) -
我确实按照您的建议将
spring.jpa.hibernate.ddl-auto设置为update。它在创建表格的意义上起作用。但问题是,我不知道在哪里!我通过应用程序填充了一些数据,但是当我使用 DBeaver 作为用户名连接到数据库时,我看到了公共架构,但什么也没有。就像有一个隐藏的模式,其中包含表格和 Hibernate 创建的数据。我迷路了! -
最后是数据库名称的问题。我不明白它如何在本地而不是在部署时工作
标签: postgresql amazon-web-services spring-boot hibernate