Hibernate 列名中的特殊字符

Rah*_*dar 5 java postgresql hibernate

我有一个名为@id 我想执行此查询的列的表:

select DISTINCT "@id" from "osm_art_center"
Run Code Online (Sandbox Code Playgroud)

在 Java(休眠)中。

问题是 Hibernate 无法理解@id并返回 id 列不存在的错误。

编辑

导致错误的代码:

String columnName="@id";
String tableName="osm_art_center";
ResultSet polygonSearch;
polygonSearch = st.executeQuery("select DISTINCT "+columnName+" from "+tableName);
Run Code Online (Sandbox Code Playgroud)

已抛出的错误:

SQL Error: org.postgresql.util.PSQLException: ERROR: column "id" does not exist
Run Code Online (Sandbox Code Playgroud)

pau*_*sm4 3

尝试引用列名称:

String sql ="select DISTINCT \"@id\" from osm_art_center;
ResultSet polygonSearch = st.executeQuery(sql);
Run Code Online (Sandbox Code Playgroud)

Java 语言不会剥离或更改字符串中的“@”字符。然而,您使用的 JDBC 驱动程序的行为完全有可能与您的 PostgreSQL 命令解释器不同。

无论哪种方式,请尝试转义特殊字符。