简体   繁体   English

使用 JPA 本机查询实现 json_exists 时出现问题

[英]Issue while implementing json_exists using JPA Native query

My Query looks like below,我的查询如下所示,

@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)

When i am getting below error while execution of this query当我在执行此查询时遇到错误时

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

Can anyone please help.任何人都可以请帮忙。

I fixed the issue.我解决了这个问题。 Problem was with the way i was storing the Json Object in database.问题在于我在数据库中存储 Json Object 的方式。 I was storing the value in db as ["50000021","50000022"] which in fact is a valid json, and was trying to execute my query to provide result, which was resulting in error.我将 db 中的值存储为 ["50000021","50000022"] 这实际上是一个有效的 json,并试图执行我的查询以提供结果,这导致了错误。 When i stored data in this format, { "ReferenceDataId": ["50000021","50000022"] } below query successfully executed.当我以这种格式存储数据时,{ "ReferenceDataId": ["50000021","50000022"] } 下面的查询成功执行。 – Ritesh 1 min ago Edit Delete – 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM