# Why is Right Join not supported by Hibernate and JPA?

**URL:** <https://discourse.hibernate.org/t/why-is-right-join-not-supported-by-hibernate-and-jpa/6571>\
**Category:** Hibernate ORM\
**Created:** [August 6, 2022, 12:13am UTC](https://discourse.hibernate.org/t/why-is-right-join-not-supported-by-hibernate-and-jpa/6571 "2022-08-06T00:13:10Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![Vamshs](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vamshs/32/1969_2.png) [@Vamshs](https://discourse.hibernate.org/u/Vamshs)\
**Post date:** [August 8, 2022, 12:39pm UTC](https://discourse.hibernate.org/t/why-is-right-join-not-supported-by-hibernate-and-jpa/6571/8 "2022-08-08T12:39:58Z")

</div>

@beikov - The Entity Mapping for Packages and ProtectedItems are like as in the Question part (not yet as suggested by you in the comments) of this [post](https://discourse.hibernate.org/t/org-hibernate-mappingexception-repeated-column-in-mapping-for-collection-com-abc-entities-packages-protecteditems-column-account-id/6516). The mapping for ProtectedItems and StreamMapping is similar to above mapping.

The criteria query joins are like below and the Hibernate Version is 5.6.9

```auto
Root<StreamMappings> root = query.from(StreamMappings.class);
Join<StreamMappings, ProtectedItems> protectedItemsJoin = root.join("protectedItemsList", JoinType.LEFT);
Join<ProtectedItems, Packages> packagesJoin = protectedItemsJoin.join("packagesList", JoinType.LEFT);

```

Generated Query -

```auto
select
        distinct cast(streammapp0_.stream_id as char) as col_0_0_,
        streammapp0_.stream_name as col_1_0_,
        cast(packages4_.package_id as char) as col_2_0_,
        packages4_.package_name as col_3_0_,
        streammapp0_.created_at as col_4_0_,
        streammapp0_.last_modified_at as col_5_0_ 
    from
        stream_mappings streammapp0_ 
    left outer join
        jt_protected_items_stream_mappings protectedi1_ 
            on streammapp0_.account_id=protectedi1_.ci_account_id 
            and streammapp0_.content_id_extension=protectedi1_.content_id_extension 
    left outer join
        protected_items protectedi2_ 
            on protectedi1_.pi_account_id=protectedi2_.account_id 
            and protectedi1_.protected_item_id=protectedi2_.protected_item_id 
    left outer join
        jt_packages_protected_items packagesli3_ 
            on protectedi2_.account_id=packagesli3_.pi_account_id 
            and protectedi2_.protected_item_id=packagesli3_.protected_item_id 
    left outer join
        packages packages4_ 
            on packagesli3_.p_account_id=packages4_.account_id 
            and packagesli3_.package_id=packages4_.package_id 
    where
        streammapp0_.account_id=? 
    order by
        cast(streammapp0_.stream_id as char) asc,
        cast(packages4_.package_id as char) asc limit ?

```

The problem is in below data - line 1 should be elimated and using right join this is possible as the right join on streammapping happens at the last.

```auto
Xcain3x(streamId=4009, streamName=IPL-HD, packageId=null, packageName=null, createdAt=2022-06-19T00:00:00Z, lastModifiedAt=2022-06-19T00:00:00Z)
Xcain3x(streamId=4009, streamName=IPL-HD, packageId=2, packageName=Package-2, createdAt=2022-06-19T00:00:00Z, lastModifiedAt=2022-06-19T00:00:00Z)
Xcain3x(streamId=4009, streamName=IPL-HD, packageId=4, packageName=Package-4, createdAt=2022-06-19T00:00:00Z, lastModifiedAt=2022-06-19T00:00:00Z)

```

---

_[View the full topic](https://discourse.hibernate.org/t/why-is-right-join-not-supported-by-hibernate-and-jpa/6571)._
