【问题标题】:while querying through createNativeQuery() with a column name which is a mixed of uppercase and lower case is getting converted into lower case [duplicate]在通过 createNativeQuery() 查询时,列名混合了大写和小写的列名被转换为小写 [重复]
【发布时间】:2022-01-03 15:09:17
【问题描述】:

在通过 createNativeQuery() 查询时,使用混合了大写和小写的列名被转换为小写。下面是我的代码

Query query = entityManager.createNativeQuery("SELECT distinct a.admission_type_L1 FROM admission_type a");
    List<String> result=query.getResultList();

我得到的错误如下

Hibernate: SELECT distinct a.admission_type_L1 FROM admission_type a                                                                                                        
2021-11-25 15:28:21.646  WARN 2600 --- [  XNIO-1 task-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 0, SQLState: 42703                                           
2021-11-25 15:28:21.647 ERROR 2600 --- [  XNIO-1 task-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : ERROR: column a.admission_type_l1 does not exist                          
Hint: Perhaps you meant to reference the column "a.admission_type_L1".

它说 admission_type_l1 不存在,但我正在通过 admission_type_L1

如果我使用没有大写的列名,它可以正常工作

我的数据库是 postgreqsl

【问题讨论】:

    标签: postgresql spring-boot entitymanager nativequery quoted-identifier


    【解决方案1】:

    PostgreSQL 将所有表列名转换为小写,除非被引用。

    要在模式操作中保留自然大小写,必须引用标识符。

    更多信息可以参考这个链接:https://www.drupal.org/project/drupal/issues/1600670

    【讨论】:

      猜你喜欢
      • 2015-05-26
      • 2012-12-01
      • 1970-01-01
      • 2018-01-11
      • 2015-11-28
      • 2011-10-08
      • 1970-01-01
      • 2017-03-04
      • 2018-04-24
      相关资源
      最近更新 更多