Open dsarlo-viso opened 3 months ago
Pulling a collection into an entity view that relies on hibernate's OrderColumn is not in order.
The collection should be ordered by the OrderColumn
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)")
@MappingIndex("INDEX(this)")
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(); } }
Version: 1.6.11 JPA-Provider: Hibernate 5.6.15.Final DBMS: PostgreSQL 13.3 Application Server: Spring Boot 2.7.18
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:
Child entity:
EntityView (non-creatable non-updatable just for response):
Environment
Version: 1.6.11 JPA-Provider: Hibernate 5.6.15.Final DBMS: PostgreSQL 13.3 Application Server: Spring Boot 2.7.18