Spring Data @EntityGraph performs LEFT OUTER JOIN instead of INNER JOIN
Having following parent-child entity definitions, when using Spring’s @EntityGraph
performs a LEFT OUTER JOIN
instead of an INNER JOIN
.
@Entity public class Parent { @Id @Column(name = "gid", updatable = false, nullable = false, columnDefinition = "...") private UUID id = UUID.randomUUID(); @ManyToOne(fetch = FetchType.LAZY, optional = false) @JoinColumn(name = "type_id", nullable = false, columDefinition='...') private Type type; // ...
@Entity public class Type { @Id @Column(name = "gid", updatable = false, nullable = false, columnDefinition = "...") private UUID id = UUID.randomUUID(); // ...
public interface ParentRepository extends JpaRepository<Parent, UUID> { @EntityGraph(attributePaths = "type") Optional<Parent> findOneWithTypeById(UUID id);
The ParentRepository#findOneWithTypeById
results in a LEFT JOIN
although I specied type
is optional=false
and nullable=false
.
There should be enough information for Spring/JPA to generate a query with an INNER JOIN here ?