'Spring boot JPA - EntityGraph - cross join to left outer join

I have some classes, performing some queries with Entity Graph. The code is generating a cross join ... that I would like to change to left outer join.

Is this possible ?

So I got a this Classes

@Table(schema = "public", name = "parent")
public class Parent implements Serializable {

@Id
private Long id;

@Column(name = "created_at", updatable = false)
private LocalDateTime createdAt;

@ManyToOne
@JoinColumn(name = "child1")
private Child1 child1;

@ManyToOne
@JoinColumn(name = "child2")
private Chil child2;

@ManyToOne
@JoinColumn(name = "child3")
private Child3 child3;

@OneToOne(mappedBy = "Parent")
private Child4 child4

}

....

@Entity
@Table(schema = "public", name = "child4")
public class Child4 implements Serializable {

@Id
private Long parentId;

private boolean printed;

private boolean read;

private boolean done;

@OneToOne
@PrimaryKeyJoinColumn(name = "parent_id", referencedColumnName = "parent_id")
private Parent parent;
}

then I got this repository

@Repository
public interface ParentRepository extends JpaRepository<Parent, Long>, 
QuerydslPredicateExecutor<Parent> {

@EntityGraph(
        type = EntityGraph.EntityGraphType.FETCH,
        attributePaths = {
                "child1",
                "child2",
                "child3",
                "child4"
        }
)
Page<Interrogation> findAll(Predicate predicate, Pageable pageable);

}

and this is SQL result

select 
.....
from
public.parent parent0_ 
left outer join
  public.child1 child1_ 
  on parent0_.child1_id = child1_.id 
left outer join
  public.child2 child2_ 
  on parent0_.child2_id = child2_.id 
left outer join
  public.device child3_ 
  on parent0_.child3_id = child3_.id 
cross join
  child4 child4_ 
where
  parent.id = child4_.parent_id 

My issue that I'd like to change the cross join with a left join ...

is that possible ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source