postgresql - 仅在 Linux 中;org.postgresql.util.PSQLException:错误:关系“table_name”不存在
问题描述
我一直在寻找 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.datasource.url=jdbc:postgresql://${RDS_HOSTNAME}:${RDS_PORT}/${RDS_DB_NAME}
# ...
spring.datasource.username=${RDS_USERNAME}
spring.datasource.password=${RDS_PASSWORD}
你的 Spring Boot,PostgreSQL 是什么版本?
这是样本
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres_demo
spring.datasource.username=postgres
spring.datasource.password=123456
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto=update
注意:不要使用org.hibernate.dialect.PostgreSQL10Dialect
,使用
spring.jpa.database=org.hibernate.dialect.PostgreSQLDialect
推荐阅读
- html - R Shiny:有没有办法通过 DashboardPagePlus 执行 HTML?
- php - 处理 json 解码数组时出现非法字符串偏移
- ssh - 是否可以在不附加的情况下查看屏幕会话的内容?
- sql-server - 数据仓库/BI 建模:事实还是维度?
- ruby-on-rails - 如何安全地更改 rails 项目的目录?
- jquery - 光滑的滑块。将两个滑块同步到一个自定义附加点
- mysql - 创建一个存储过程,将具有相同键的行转换为列
- java - 静态方法按字母升序排序
- java - 使用 Google PLACES Api 搜索查看自动完成建议
- batch-file - 想要编写一个批处理作业来检查计算机是否处于锁定状态(屏幕保护程序即将到来)并执行必要的操作?