I have an Entity such as:
@Entity
class Brand {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false, columnDefinition = "BIGINT")
private Long id;
@NotNull(message = NOT_NULL_CODE)
@Size(min = 5, max = 150, message = SIZE_CODE)
@Column(nullable = false, length = 150)
private String name;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "organization_id", nullable = false)
@JsonBackReference("organization-brands")
private Organization organization;
// getters and setters
}
My repository has the following defined:
Page<Brand> findAllByOrganization(Organization organization, Pageable pageable);
This results in the following query:
select
brand0_.id as id1_1_,
brand0_.name as name2_1_,
brand0_.organization_id as organiza3_1_
from
brand brand0_
left outer join
organization organizati1_
on brand0_.organization_id=organizati1_.id
where
organizati1_.id=? limit ?
I'm wondering why there is a left outer join
created? I thought maybe it was because the organization_id
was part of the select so I created a DTO Projection that only included the name
and id
columns, but that still included the left outer join
. I found this bug report filed but there's been zero movement on it.
The reason this is concerning for me is because the left outer join
adds, on average, 200ms to the query. I haven't done any benchmarking to determine if this grows exponentially with more rows of data or not. But with my current dataset, it's 200ms. Yikes.