Skip to content

Instantly share code, notes, and snippets.

@yannbriancon
Last active May 2, 2020 17:53
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Criteria query with JoinType LEFT
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