So, After a 10+ year break I\'m coming back to Java and trying out stuff with JPA and Java generics. I\'ve created a generics based findAll(other) JPA query tha
Hat tip to Adam Bien if you don't want to use createQuery with a String and want type safety:
@PersistenceContext EntityManager em; public ListallEntries() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(ConfigurationEntry.class); Root rootEntry = cq.from(ConfigurationEntry.class); CriteriaQuery all = cq.select(rootEntry); TypedQuery allQuery = em.createQuery(all); return allQuery.getResultList(); }
http://www.adam-bien.com/roller/abien/entry/selecting_all_jpa_entities_as