'Hibernate envers revision throws exception when use @OrderBy

I have 2 entities and use Hibernate envers and Spring envers for auditing

@Data
@ToString(exclude = {"groupReportPrices"})
@EqualsAndHashCode(exclude = {"groupReportPrices"})
@NoArgsConstructor
@AllArgsConstructor
@Builder
@With
@Entity
@Table(name = "CLIENT_GROUP")
@AuditTable("CLIENT_GROUP_HISTORY")
@Audited
public class GroupEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "clientGroupIdSeq")
    @SequenceGenerator(name = "clientGroupIdSeq", sequenceName = "CLIENT_GROUP_ID_SEQ", allocationSize = 1)
    @Column(name = "CLIENT_GROUP_ID")
    private Long id;
    @NotNull
    private String name;
    @NotNull
    private boolean active;
    @Fetch(value = FetchMode.SUBSELECT)
    @OneToMany(mappedBy = "group", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
    @OrderBy("groupReportPriceId")
    private List<GroupReportPriceEntity> groupReportPrices;
}
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(exclude = {"group"})
@ToString(exclude = {"group"})
@Builder
@Entity
@Table(name = "GROUP_PAY_GO_PRICE")
@Audited
@AuditTable("GROUP_PAY_GO_PRICE_HISTORY")
@EntityListeners(AuditingEntityListener.class)
public class GroupReportPriceEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "groupPayGoPriceGenerator")
    @SequenceGenerator(name = "groupPayGoPriceGenerator", sequenceName = "GROUP_PAY_GO_PRICE_ID_SEQ", allocationSize = 1)
    @Column(name = "GROUP_PAY_GO_PRICE_ID")
    private Long groupReportPriceId;
    @NotNull
    private BigDecimal price;
    @NotNull
    @Convert(converter = ProductTypeConverter.class)
    private ProductType reportType;
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    @JoinColumn(name = "CLIENT_GROUP_ID", nullable = false)
    private GroupEntity group;
}

When I'm trying to get revision of nested entities

Optional<Revision<Long, GroupEntity>> lastChangeRevision = groupRepository.findLastChangeRevision(revisionId);
List<GroupReportPriceEntity> groupReportPrices = lastChangeRevision.get().getEntity().getGroupReportPrices();

I receive the following error

org.hibernate.QueryException: could not resolve property: groupReportPriceId of: com.corelogic.spatial.persistence.domain.GroupReportPriceEntity_AUD [select e__ from com.corelogic.spatial.persistence.domain.GroupReportPriceEntity_AUD e__ where e__.group_id = :group_id and e__.originalId.REV.id = (select max(e2__.originalId.REV.id) from com.corelogic.spatial.persistence.domain.GroupReportPriceEntity_AUD e2__ where e2__.originalId.REV.id <= :revision and e__.originalId.groupReportPriceId = e2__.originalId.groupReportPriceId) and REVTYPE != :delrevisiontype order by e__.groupReportPriceId]

It works fine if I delete @OrderBy("groupReportPriceId") from GroupEntity class. Also, it's worked even with OrderBy annotation on previous versions of dependencies Spring envers - 2.2.12.Final, Hibernate and Hibernate envers - 5.2.17.Final. After migration Spring envers to 2.6.0, Hibernate and Hibernate envers to 5.6.8.Final I started to receive exception. I tried to use OrderBy from javax.persistence and from org.hibernate.annotations, but results are the same.

Am I doing something wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source