{"id":138,"date":"2020-01-23T10:14:10","date_gmt":"2020-01-23T10:14:10","guid":{"rendered":"http:\/\/buki.io\/?p=138"},"modified":"2021-05-11T10:51:54","modified_gmt":"2021-05-11T09:51:54","slug":"jpql-with-left-outer-join","status":"publish","type":"post","link":"http:\/\/buki.io\/?p=138","title":{"rendered":"JPQL with left outer join"},"content":{"rendered":"<p>To remind my self!<br \/>\nMain.class <code><br \/>\n@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; }<br \/>\n<\/code><br \/>\nDepending.class <code><br \/>\n@Id<br \/>\n@Column(name = \" column_name_in_depeding_table\", nullable = true)<br \/>\npublic int getDescriptionId() { return descriptionId; }<br \/>\n@Column(name =\"language) Public String getLanguage(){return language;}<br \/>\n<\/code><br \/>\nNow if I want something like<\/p>\n<p><code> 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<br \/>\n<\/code><br \/>\nYou have to put the where-criteria directly into the &#8222;left join&#8220; 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&#8217;t tried Hibernate) creates and &#8222;old-style&#8220; (ANSI-89) style query, where the join condition is put in the where-clause and you won&#8217;t get any results!<\/p>\n<p><code> @NamedQueries({ @NamedQuery(name = Main.FIND_BY_ID, query = \"SELECT c FROM Main c left join c.description des on des.language = :language where c.id = :id\")} <\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>To remind my self! Main.class @OneToOne @JoinColumn(name = &#8222;pk_column_name_in_main_table&#8220;, referencedColumnName = &#8222;column_name_in_depeding_table&#8220;, insertable = false, updatable = false) public Description getDescription() { return this.description; } Depending.class @Id @Column(name = &#8220; column_name_in_depeding_table&#8220;, nullable = true) public int getDescriptionId() { return descriptionId; } @Column(name =&#8220;language) Public String getLanguage(){return language;} Now if I want something like Select * &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/buki.io\/?p=138\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8222;JPQL with left outer join&#8220;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[3],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7N2pi-2e","_links":{"self":[{"href":"http:\/\/buki.io\/index.php?rest_route=\/wp\/v2\/posts\/138"}],"collection":[{"href":"http:\/\/buki.io\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/buki.io\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/buki.io\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/buki.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=138"}],"version-history":[{"count":2,"href":"http:\/\/buki.io\/index.php?rest_route=\/wp\/v2\/posts\/138\/revisions"}],"predecessor-version":[{"id":149,"href":"http:\/\/buki.io\/index.php?rest_route=\/wp\/v2\/posts\/138\/revisions\/149"}],"wp:attachment":[{"href":"http:\/\/buki.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/buki.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=138"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/buki.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}