Created
September 30, 2021 07:41
-
-
Save madgrk/e47d3bacc87515689dbc3f6156636643 to your computer and use it in GitHub Desktop.
Selecting all jpa entities as selection query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@PersistenceContext | |
EntityManager em; | |
protected Class<T> type; | |
public List<T> allEntries() { | |
CriteriaBuilder cb = em.getCriteriaBuilder(); | |
CriteriaQuery<T> cq = cb.createQuery(type); | |
Root<T> rootEntry = cq.from(type); | |
CriteriaQuery<T> all = cq.select(rootEntry); | |
TypedQuery<T> allQuery = em.createQuery(all); | |
return allQuery.getResultList(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment