首页 > 解决方案 > 在使用 camelCase 定义的数据库中时,PostgreSQL“列不存在”

问题描述

我对 Postgres 有一个有趣的情况(类似于PostgreSQL“列不存在”,但它确实存在)。即列或表名包含大写字母。在上面的给定链接中,它是关于表名的。

就我而言,在数据库中,我在 camelCase 中定义了一个列“projectId”(数据库中的 SQL 看起来像“..“projectId”整数 NOT NULL,..')。在后端我使用 Java 和 Hibernate。当我尝试使用命名查询(例如“SELECT e FROM ProjectTa e”)获取表的所有条目时,我收到错误消息:

org.hibernate.exception.SQLGrammarException: could not extract ResultSet
Caused by: org.postgresql.util.PSQLException: ERROR: column projectta0_.projectid does not exist
  Hinweis: Perhaps you meant to reference the column "projectta0_.projectId".
  Position: 138

SQL 日志:

select projectta0_.id as id1_1_, projectta0_.budget as budget2_1_, projectta0_.completion as completi3_1_, projectta0_.name as name4_1_, projectta0_.projectId as projectI5_1_, p
rojectta0_.status as status6_1_, projectta0_.users as users7_1_ from project_ta projectta0_

'FROM "Tablename" ' 将解决表名问题。如果我只想要表的所有条目,我必须如何调整我的命名查询。(我不想在我的实体中更改列名或使用 @Column 的名称)

标签: postgresqlhibernatequoted-identifier

解决方案


推荐阅读