I have a table with reflexive association:
A container could be associated to a parent (Column container_id). A container can have containers as child.
@Entity
public class Container implements Serializable {
@ManyToOne
@JoinColumn(name = "container_id", nullable = true, referencedColumnName = "original_id")
private Container containedIn;
@Column(name = "original_id")
private long originalId;
@OneToMany(mappedBy = "containedIn")
private List<Container> contains = new ArrayList<>();
...
Problem:
The generated request is :
Hibernate: select * from (
select *
from container con0_, container con1_
where con0_.container_id=con1_.original_id
order by con1_.code ) where rownum <= ?
where i'm expecting left outer join:
from container con0_ left outer join container con1_
on con0_.container_id=con1_.original_id.
Container that doesn't have parent (Root Box CON0000007) are not retrieved as left join is not generated by Hibernate:
ID | ORIGINAL_ID| CODE | TYPE | CONTAINER_ID (Parent)
1 | 2 | CON000000002 | Package | 12
2 | 4 | CON000000004 | Package | 10
4 | 6 | CON000000006 | Package | 11
5 | 8 | CON000000008 | Package | 10
7 | 10 | CON0000002 | Box | 15
8 | 11 | CON0000003 | Box | 15
9 | 12 | CON0000004 | Box | 15
12 | 15 | CON0000007 | Root Box | NULL