# RIGHT Join in Hibernate Criteria API

**URL:** <https://discourse.hibernate.org/t/right-join-in-hibernate-criteria-api/9152>\
**Category:** Hibernate ORM\
**Created:** [March 7, 2024, 12:34pm UTC](https://discourse.hibernate.org/t/right-join-in-hibernate-criteria-api/9152 "2024-03-07T12:34:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oleksandr](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/oleksandr/32/3073_2.png) [@Oleksandr](https://discourse.hibernate.org/u/Oleksandr)\
**Post date:** [March 7, 2024, 12:34pm UTC](https://discourse.hibernate.org/t/right-join-in-hibernate-criteria-api/9152/1 "2024-03-07T12:34:26Z")

</div>

Hello, I am facing an issue where I need to incorporate a right join in the Criteria API. Due to the project limitation I can’t use Hibernate 6+.

I want to have the fsmth following:  
` final var groupJoin = root.join("Some entitiy" JoinType.RIGHT);`  
It appears that Hibernate does not support this type of join.  
Any workarounds would be greatly appreciated.

Here is my basic entity structure:

```auto
@Entity
public class Label {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "label")
    private Set<LabelSupplier> labelSuppliers = new HashSet<>();
    // Additional fields and methods...
}

@Entity
public class LabelSupplier {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne
    @JoinColumn(name = "label_id", nullable = true) // Notable for allowing nulls
    private Label label;
    // Additional fields and methods...
}

```

Actually, my task is to return the duplicated parent for each child. You can suggest querying a parent in the given scenario, then iterating over a collection of children, placing all this information into a resource dto, and ultimately returning it to the client. However, this approach is not viable for me. In such a scenario, another issue could arise when the client attempts to set the size parameter, specify a query URL size parameter, or utilize some Spring Boot pagination features.

In conclusion, I would like to retrieve each LabelSupplier If there is no Label for certain LabelSupplier - just return LabelSupplier with null label

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [March 7, 2024, 12:43pm UTC](https://discourse.hibernate.org/t/right-join-in-hibernate-criteria-api/9152/2 "2024-03-07T12:43:24Z")

</div>

Use HQL or upgrade to Hibernate ORM 6. ORM 5 is only receives limited support at this time. Also see [5.6 series - Hibernate ORM](https://hibernate.org/orm/releases/5.6/) and [Maintenance Policy - Hibernate](https://hibernate.org/community/maintenance-policy/) for details.

---

<div class="post-metadata">

**Author:** ![Oleksandr](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/oleksandr/32/3073_2.png) [@Oleksandr](https://discourse.hibernate.org/u/Oleksandr)\
**Post date:** [March 7, 2024, 12:45pm UTC](https://discourse.hibernate.org/t/right-join-in-hibernate-criteria-api/9152/3 "2024-03-07T12:45:25Z")

</div>

As mentioned, I cannot use Hibernate 6. Are any additional options possible here?

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [March 7, 2024, 12:56pm UTC](https://discourse.hibernate.org/t/right-join-in-hibernate-criteria-api/9152/4 "2024-03-07T12:56:10Z")

</div>

Like I wrote, you can use HQL.

---

<div class="post-metadata">

**Author:** ![Oleksandr](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/oleksandr/32/3073_2.png) [@Oleksandr](https://discourse.hibernate.org/u/Oleksandr)\
**Post date:** [March 7, 2024, 12:59pm UTC](https://discourse.hibernate.org/t/right-join-in-hibernate-criteria-api/9152/5 "2024-03-07T12:59:30Z")

</div>

In my application, clients are allowed to pass different parameters using the URL. This is why HQL won’t be a suitable solution. Could it be possible to merge HQL and the Criteria API?

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [March 13, 2024, 1:02pm UTC](https://discourse.hibernate.org/t/right-join-in-hibernate-criteria-api/9152/6 "2024-03-13T13:02:36Z")

</div>

HQL is built on top of the Criteria API in ORM 6.
