JPQL with left outer join

To remind my self!
@OneToOne @JoinColumn(name = "pk_column_name_in_main_table", referencedColumnName = "column_name_in_depeding_table", insertable = false, updatable = false) public Description getDescription() { return this.description; }

Depending.class @Id @Column(name = " column_name_in_depeding_table", nullable = true) public int getDescriptionId() { return descriptionId; }
@Column(name ="language) Public String getLanguage(){return language;}

Now if I want something like
Select * from main m join depending d on m.pk_column_in_main_table = d.column_name_in_depending_table where d.column_name_in_depending_table is null
You have to put the where-criteria directly into the „left join“ condition of the jqpl query. If you do it like in SQL and put it in the where-clause, JPA (or at least Eclipselink, haven’t tried Hibernate) creates and „old-style“ (ANSI-89) style query, where the join condition is put in the where-clause and you won’t get any results!
@NamedQueries({ @NamedQuery(name = Main.FIND_BY_ID, query = "SELECT c FROM Main c left join c.description des on des.language = :language where = :id")}

Schreibe einen Kommentar