0
I have a method that takes as parameter an array of values(id) and I need to do a query in the database to return only the rows of a column with these values(id) I have this method:
public List<Lotacao> localizarPorId(long[] id){
try {
String sql = "select l from Lotacao l where l.id in :id";
TypedQuery<Lotacao> q = em.createQuery(sql, Lotacao.class);
for( int i = 0; i < id.length; i++) {
q.setParameter("id", id[i]);
}
return q.getResultList();
}catch(NoResultException e) {
return new ArrayList<>();
}
}
However, it only returns from the database the line that corresponds to the value of the last index of the Array. Does anyone know how to get it to return all the corresponding BD lines in the Array values?