Using an array in a JPQL query

How can I use a list of arrays in a JPQL query? I want something like this: I pass this

private static final String[] MASKS = {"30109", "30111"};

at

public List<Account> findAccount(String[] Masks){
StringBuilder sb = new StringBuilder("from AccountTable a where SUBSTRING(a.Account,1,5) in :Masks ");
Query q = em.createQuery(sb.toString(), AccountTable.class)
                .setParameter("Masks",Masks);
}

currently error

Encountered array-valued parameter binding, but was expecting [java.lang.String (n/a)]; nested exception is java.lang.IllegalArgumentException: Encountered array-valued parameter binding, but was expecting [java.lang.String (n/a)]
+4
source share
1 answer

Reading this site seems possible, but your array should be Collectionsomething like this:

public List<Account> findAccount(String[] Masks){
    StringBuilder sb = new StringBuilder("from AccountTable a where SUBSTRING(a.Account,1,5) in :Masks ");
    Query q = em.createQuery(sb.toString(), AccountTable.class)
                .setParameter("Masks", Arrays.asList(MASKS));
}

Gotta help you.

+9
source

Source: https://habr.com/ru/post/1599237/


All Articles