Well, I have a question here at JPA. Today I have a method to fetch the UFs by ID, as in the example below:
public Uf consulta(Integer id) {
EntityManager em = getEM();
Uf uf = new Uf();
try {
em.getTransaction().begin();
uf = em.find(Uf.class, id);
em.getTransaction().commit();
} catch (Exception e) {
em.getTransaction().rollback();
} finally {
em.close(); //fecha o EntityManager
}
return uf;
}
Is there a way to search all bank records without having to go through them one by one? My idea is to present all the records in a table, but I do not know if I need to consult one by one with find inside a for and add in Array for example, or if there is any way in jpa that brings everything to me without needing of a for. Any hint will be helpful.