I'm trying to write a native query in JPA. I want to verify if an element exists in a jsonb
column. However, I'm getting the error integer <@ jsonb
.
This is my query:
@Query(
value = "SELECT u FROM user u WHERE (u.depNum = ?1 and superAdmin = true " +
" and ?2 <@ (u.listUsers)) ",
nativeQuery = true
)
public List<EbUser> selectSuperAdmin(Integer depNum, Integer userNum);
The error happens here: ?2 <@ (u.listUsers)
. How can I verify that listUsers
contains the userNum
or how can I convert the userNum
to jsonb
in Java?
You can do the conversion in PostgreSQL.
and to_jsonb(ARRAY[?2]) <@ (u.listUsers))
as long as JPA doesn't interfere with passing this construct into PostgreSQL, I have not tested that part.
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.