I am using EntityManager
in spring boot app to get result from this query
select (c.data::jsonb)->>'employee_Id' as empId from employee e where e.dept ='employee' and (e.data::jsonb)->>'section_id' = '1235'
Its giving me correct output in PgAdmin
but in java code
List resultList = em.createNativeQuery(str).setParameter(1, sectionId ).getResultList();
Giving error ERROR: syntax error at or near ":"
its breaking at data::jsonb
.How do handle this using EntityManager
.
Advertisement
Answer
You need to CAST
like CAST(c.data as jsonb)->>'product_id'
from string
to JSONB
. However i would highly suggest that you don’t use TEXT
for your JSON
type data.
ALTER TABLE employee ALTER COLUMN data TYPE JSON USING data::JSON;
`