I have a query like this that works well :
"SELECT * FROM elements we WHERE jsonb_exists_all(CAST(we.elements AS jsonb), ARRAY['TEST'])"
I need to use the .setParameter method from EntityManager to insert a whole array instead of ["CHEST"] e.g. ["TEST", "TEST1", "TEST2"]. It seems to me that .setParameter converts the argument into a string. So far I have only found a workaround for assigning 2 values to the same key:
String queryFromFilter = "SELECT * FROM elements we WHERE jsonb_exists_all(CAST(we.elements AS jsonb), ARRAY[:array])";
Query query = entityManager.createNativeQuery(queryFromFilter, Checklist.class);
return query
.setParameter("array", "TEST'")
.setParameter("array", "TEST")
.getResultList();
}
2
Answers
rather the problem here is that the value from the .setParameters method puts the parameter in '' e.g. 'exampleParameter' and I need it not to be ''
This question seems related to this one where it’s suggested to convert the list of Strings into a single-quoted comma-separated String and then passing the String onto JPA Query.
For instance: