Reputation: 1154
How can I use an array list in JPQL query? I want something like this: I am passing this
private static final String[] MASKS = {"30109", "30111"};
into
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 is
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)]
Upvotes: 11
Views: 10910
Reputation: 2667
Reading this site it seems that is possible, but your array must be a Collection
, maybe something 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));
}
Should help you.
Upvotes: 24