简体   繁体   中英

JPA / JPQL data list injection

I'm trying to get somthing like this in JPA:

SELECT ...
FROM Entity e 
WHERE e.values IN (:values)

Resulting in the execution of this:

SELECT ...
FROM TABLE 
WHERE VALUES IN (1,2,3,4)

Does anybody know how to do this?

I'll be very grateful.

You can use a list as a parameter, this is an example to show how to set the parameter in the query:

        TypedQuery<Entity> query = em.createQuery("select e from Entity e where e.value IN :values", Entity.class);
        List<Integer> list = Arrays.asList(new Integer[]{1, 2, 3, 4});
        query.setParameter("values", list);
        List<Entity> results = query.getResultList();

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