In my Oracle-database table mytable I have a column columnx with JSON-Arrays (VARCHAR2) and I would like to find all entries where the value valueX is inside that array.
In native Oracle-SQL the following query is working very well:
SELECT * FROM mytable t WHERE JSON_EXISTS(columnx, '$?(@ == "valueX")');
In my Spring Boot Application I write queries in JPQL, so I have to convert it.
The following queries were unsuccessful:
I found out that I have to use 'FUNCTION()' for specific SQL-Oracle-functions:
@Query(value = "SELECT t FROM mytable t WHERE FUNCTION('JSON_EXISTS',t.columnx, '$?(@ == \"valueX\")')")That results in a JPQL-Parsing-Error: "QuerySyntaxException: unexpected AST node: function (JSON_EXISTS)"I found out that JPQL needs a real boolean-comparison, so I tried this:
@Query(value = "SELECT t FROM mytable t WHERE FUNCTION('JSON_EXISTS',t.columnx, '$?(@ == \"valueX\")') = TRUE")Now the JPQL-Converter can parse it to native SQL successfully, but I got an Oracle-Error while executing the query: "ORA-00933: SQL command not properly ended." That's understandable since the parsed native... WHERE JSON_EXISTS(columnx, '$?(@ == "valueX")') = 1won't run either.
What is the right way to solve this problem? Do you have any idea?
EDIT: This is the field definition in JAVA:
@TypeDef(name = "json", typeClass = JsonType.class)
public class Mytable {
...
@NotNull
@Type(type = "json")
@Column(columnDefinition = "VARCHAR2")
private List<String> columnx;