---
title: "How to emulate LEFT JOIN FETCH using projections"
url: https://daily.dev/posts/how-to-emulate-left-join-fetch-using-projections-z5aul2lhn
source_url: https://vladmihalcea.com/emulate-left-join-fetch-using-projections/
type: article
source: "Vlad Mihalcea"
published: 2026-02-27T09:00:21.117Z
updated: 2026-02-27T09:00:54.341Z
tags: ["java"]
reading_time: 5
upvotes: 2
comments: 0
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How to emulate LEFT JOIN FETCH using projections

**[Vlad Mihalcea](https://daily.dev/sources/vladmihalcea)** · 5 min read · 2 upvotes · 0 comments

## Summary

When you need to fetch a root entity along with an optionally associated entity through an intermediate join table, standard LEFT JOIN FETCH won't work if the intermediate entity is optional. The solution uses a JPQL query with a Record-based projection (Java Record) that wraps both the root entity and the optional entity. The fetched entities remain managed by the Persistence Context, so dirty checking and automatic flushing still work. This approach avoids fetching the intermediate entity while keeping the result entities fully managed.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://vladmihalcea.com/emulate-left-join-fetch-using-projections/>

## Similar posts on daily.dev

- [Preventing Jackson From Fetching Lazy Entity Fields](https://daily.dev/posts/preventing-jackson-from-fetching-lazy-entity-fields-no0gt58zg) · Baeldung · 0 upvotes · 0 comments

---

Tags: [#java](https://daily.dev/tags/java)

[View this post on daily.dev](https://daily.dev/posts/how-to-emulate-left-join-fetch-using-projections-z5aul2lhn)
