简体   繁体   中英

Error while getting sql record using EntityManager

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 .

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;

`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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