Last active
May 2, 2020 17:53
-
-
Save yannbriancon/66ee53068a24b890cd2603d214e512a4 to your computer and use it in GitHub Desktop.
Criteria query with JoinType LEFT
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
List<Message> getAllBy() { | |
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); | |
CriteriaQuery<Message> query = criteriaBuilder.createQuery(Message.class); | |
Root<Message> message = query.from(Message.class); | |
// Add fetching of the author field | |
message.fetch(Message_.author, JoinType.LEFT); | |
query.select(message); | |
TypedQuery<Message> typedQuery = entityManager.createQuery(query); | |
return typedQuery.getResultList(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment