AuditReaderImpl.getRevisions result is not ordered as specified in Javadoc

Description

The Javadoc of org.hibernate.envers.AuditReader.getRevisions specifies that results are

sorted in ascending order (so older revisions come first)??.

The implementation in org.hibernate.envers.reader.AuditReaderImpl is as follows:
return createQuery().forRevisionsOfEntity(cls, entityName, false, true).addProjection(AuditEntity.revisionNumber()).add(AuditEntity.id().eq(primaryKey)).getResultList();

The Javadoc of AuditQueryCreator.forRevisionsOfEntity specifies that

The results of the query will be sorted in ascending order by the revision number, unless an order or projection is added

Since the implementation adds a projection on the revision number, no ordering is performed, which causes randomly ordered results to be returned.

The fix looks simple: just replace the above code with
return createQuery().forRevisionsOfEntity(cls, entityName, false, true).addProjection(AuditEntity.revisionNumber()).add(AuditEntity.id().eq(primaryKey)).addOrder(AuditEntity.revisionNumber().asc()).getResultList();

Environment

None

Status

Assignee

AdamA

Reporter

Thierry Monney

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

3.6.1

Priority

Major
Configure