Hibernate Envers automatically adds a clause 'order by' by ID Revision when no projection or order is specified

Description

Hibernate Envers (Criteria API) automatically adds a clause 'order by' by ID Revision when not is added projection and not is added order. This procedure burdening the query performance for a user, resulting in a warning that the I/O limit was exceeded.

In order to allow the user to be able to disable this behaviour, I propose that the addOrder method in AbstractAuditQuery.java be updated so that if a Null value is passed as a parameter, no action occurs, but the hasOrder flag is set to true. This should not break existing queries as addOrder previously throw a NullPointerException if null was passed as a parameter.

Hence, this allows users to create an AuditQuery as follows if they do not want the 'Order By' statement:

See also: https://bugzilla.redhat.com/show_bug.cgi?id=1247316

Environment

None

Activity

Show:
Chris Cranford
March 26, 2016, 5:11 PM

, was the customer seeing this I/O limit problem because the query is effectively fetching all revisions for all entities of a particular type from the audit database without any further refinement?

I could understand one applicable use may be to replicate audit data into some analytic or external system and the ordering would be overhead. But from the general purpose use of this query, the default ordering is there to make sure that users who are interested in specific revisions of an entity get the data in some logical order.

That aside, I don't find the null approach to be a viable solution. I would argue that a better approach would be to extend the forRevisionsOfEntity method with another version that allows passing a boolean to disable the default ordering mechanism. This keeps the API contract clean, doesn't violate or have any negative side affects with the ordering api and keeps code fully backward compatible with existing uses.

Thoughts?

Ryan Emerson
March 28, 2016, 10:43 AM

I think this issue should be closed. After further discussions with the customer and @gbadner it was decided that this was not a legitimate use case.

Assignee

Gail Badner

Reporter

Ryan Emerson

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Major
Configure