【问题标题】:Issue while implementing json_exists using JPA Native query使用 JPA 本机查询实现 json_exists 时出现问题
【发布时间】:2020-07-24 01:55:11
【问题描述】:

我的查询如下所示,

@Query(value="SELECT * FROM Retention_Record retention where retention.entity=:entity and retention.category=:category and retention.record_type=:recordType and json_exists(retention.reference_data_id, '$?(@==$referenceDataId)' passing :referenceDataId as \"referenceDataId\")" , nativeQuery=true)

当我在执行此查询时遇到错误时

2020-07-23 16:12:11 [eventsTaskExecutor-5] [] WARN  o.h.e.jdbc.spi.SqlExceptionHelper - SQL Error: 29902, SQLState: 99
999
2020-07-23 16:12:11 [eventsTaskExecutor-5] [] ERROR o.h.e.jdbc.spi.SqlExceptionHelper - ORA-29902: error in executing
ODCIIndexStart() routine
ORA-20000: Oracle Text error:
DRG-50900: text query parser error on line 1, column 10
DRG-50917: escape on at end of text query string

谁能帮忙。

【问题讨论】:

  • 在Oracle数据库中能用吗?
  • 是的...在 oracle db 上它可以工作。
  • 你也可以分享那个查询吗?
  • 嗨@MuhammadWaqasDilawar,SELECT * FROM Retention_Record 保留 whereretention.entity=?和retention.category=?和retention.record_type=?和 json_exists(retention.reference_data_id, '$?(@==$referenceDataId)' 传递 ? 作为 "referenceDataId" )
  • 另外,这有效,但有问题的查询无效。
    @Query(value="SELECT * FROM Retention_Record retention where retention.entity=:entity and retention.category=:category and retention.record_type=:recordType and json_exists(retention.reference_data_id, '$?(@==50000021)' )" , nativeQuery=true)

标签: java spring spring-boot jpa spring-data-jpa


【解决方案1】:

我解决了这个问题。问题在于我将 Json 对象存储在数据库中的方式。我将 db 中的值存储为 ["50000021","50000022"] 这实际上是一个有效的 json,并试图执行我的查询以提供结果,这导致了错误。当我以这种格式存储数据时,{ "ReferenceDataId" : ["50000021","50000022"] } 下面的查询成功执行。 – Ritesh 1 分钟前 编辑 删除

@Query(value = "SELECT * FROM Retention_Record retention where retention.entity=:entity and retention.category=:category and retention.record_type=:recordType and json_exists(retention.reference_data_id, '$.ReferenceDataId?(@==$referenceDataId)' passing :referenceDataId as \"referenceDataId\")", nativeQuery = true)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-09
    • 2021-10-16
    • 1970-01-01
    • 1970-01-01
    • 2021-05-13
    • 2018-12-31
    • 2016-09-30
    • 2019-07-02
    相关资源
    最近更新 更多