Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

findLastChangeRevision doesn't return last revision if two revisions with exactly the same timestamp exist #3579

Closed
flauschtrud opened this issue Aug 13, 2024 · 3 comments
Assignees
Labels
type: bug A general bug

Comments

@flauschtrud
Copy link

While running automated tests I ran into an issue with RevisionRepository.findLastChangeRevision.

If two revisions with exactly the same timestamp exist findLastChangeRevision does not necessarily return the revision with the highest revision number (which is what I would expect).

If my revinfo table has the following content findLastChangeRevision for the associated audited entity actually returns the revision with id 1 and not the one with id 2.

id,timestamp
1,2024-08-13 08:49:48.501000
2,2024-08-13 08:49:48.501000

In the implementation the revisions are ordered based on revisionProperty("timestamp") and the ID is not taken into account.

I am aware that this is an edge case and that it's way more likely to run into it in artificial scenarios but it's also not impossible to cause issues for production code.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 13, 2024
@mp911de
Copy link
Member

mp911de commented Aug 13, 2024

Actually, shouldn't the retrieval sort by AuditEntity.revisionNumber().desc()? Identifiers could be non-incrementable types such as UUID and sorting by these wouldn't work.

@schauder
Copy link
Contributor

Hibernates documentation isn't overly clear of the semantics of the two properties.
But in the javadoc to @RevisionNumber I found Values of this property should form a strictly-increasing sequence of numbers.
And there is also this old discussion in the Hibernate forum.
https://discourse.hibernate.org/t/order-of-revision-number-in-envers/2399

So it does indeed seem that the revisionNumber should be used.

I'll fix that.

@schauder schauder added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 19, 2024
schauder added a commit that referenced this issue Aug 19, 2024
Timestamps might not be unique, but the revision number "should form a strictly-increasing sequence of numbers".

See https://docs.jboss.org/hibernate/orm/5.2/javadocs/org/hibernate/envers/RevisionNumber.html
Closes #3579
schauder added a commit that referenced this issue Aug 19, 2024
Timestamps might not be unique, but the revision number "should form a strictly-increasing sequence of numbers".

See https://docs.jboss.org/hibernate/orm/5.2/javadocs/org/hibernate/envers/RevisionNumber.html
Closes #3579
@schauder schauder added this to the 3.2.10 (2023.1.10) milestone Aug 19, 2024
@wacker
Copy link

wacker commented Oct 16, 2024

We have a regression here, as revision numbers are in fact not always sequential (at least not in a multi-node environment), because of the pre-allocation of Hibernate sequence numbers. The 'order by' should probably be composed of timestamp AND rev in order to handle the issue of exactly the same timestamps.

schauder added a commit that referenced this issue Oct 21, 2024
Sorting by revision number alone failed for distributed systems using batched sequences for revision numbers.

Closes #3643
See #3579
schauder added a commit that referenced this issue Oct 21, 2024
Sorting by revision number alone failed for distributed systems using batched sequences for revision numbers.

Closes #3643
See #3579
schauder added a commit that referenced this issue Oct 21, 2024
Sorting by revision number alone failed for distributed systems using batched sequences for revision numbers.

Closes #3643
See #3579
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

5 participants