Blazebit / blaze-persistence

Rich Criteria API for JPA providers
https://persistence.blazebit.com
Apache License 2.0
697 stars 85 forks source link

Entity view collection not respecting hibernate's OrderColumn #1867

Open dsarlo-viso opened 3 months ago

dsarlo-viso commented 3 months ago

Description

Pulling a collection into an entity view that relies on hibernate's OrderColumn is not in order.

Expected behavior

The collection should be ordered by the OrderColumn

Actual behavior

The collection on the entity view is not ordered correctly. The entity collection is correctly ordered but the entity view collection isn't.

Workaround:

Using the following on the collection in the entity view works @MappingIndex("INDEX(this)")

Steps to reproduce

Parent entity:

@Entity
@Table(name = "org")
public class Org {
    @OrderColumn(name = "leader_order", nullable = false)
    @Cascade(org.hibernate.annotations.CascadeType.ALL)
    @ElementCollection
    @CollectionTable(name = "org_leadership", joinColumns = @JoinColumn(name = "org_id"))
    private List<LeadershipContact> leadership = new ArrayList<>();
}

Child entity:

@Embeddable
public class LeadershipContact {
    @Parent
    @JsonIgnore
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "org_id", nullable = false, updatable = false)
    private Organization org;
}

EntityView (non-creatable non-updatable just for response):

@EntityView(Org.class)
public interface OrgDetailsResponse {
    @IdMapping
    Long getId();

    List<OrgDetailsResponse.LeadershipContactView> getLeadership();

    @EntityView(LeadershipContact.class)
    interface LeadershipContactView {
        String getFirstName();

        String getLastName();

        String getEmail();

        String getTitle();

        String getLinkedinUrl();
    }
}

Environment

Version: 1.6.11 JPA-Provider: Hibernate 5.6.15.Final DBMS: PostgreSQL 13.3 Application Server: Spring Boot 2.7.18