RIGHT Join in Hibernate Criteria API

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:

@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

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 and Maintenance Policy - Hibernate for details.

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

Like I wrote, you can use HQL.

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?

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