Kai Zander (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *updated* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiOTYzMDYwMmI1...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-17080?atlOrigin=eyJpIjoiOTYzMD...
) HHH-17080 (
https://hibernate.atlassian.net/browse/HHH-17080?atlOrigin=eyJpIjoiOTYzMD...
) [Envers] AuditReader.getRevisionNumberForDate(LocalDateTime) uses Epoch Seconds instead
of Epoch Millis (
https://hibernate.atlassian.net/browse/HHH-17080?atlOrigin=eyJpIjoiOTYzMD...
)
Change By: Kai Zander (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
{{AuditReader.getRevisionNumberForDate(LocalDateTime)}} delegates to
{{RevisionTimestampValueResolver.resolveByValue(LocalDateTime)}}. When the type of the
revision timestamp property in our revision entity is {{Long}}/{{long}}, the argument is
converted to epoch _seconds_
[
here|https://github.com/hibernate/hibernate-orm/blob/6.2.7/hibernate-enve...]:
{code:java}return localDateTime.atZone( ZoneId.systemDefault()
).toInstant().getEpochSecond(); // <-- should be toEpochMilli(){code}
The result is then used as the parameter in the revision number query:
{code:sql}select max(rev) from revision_info where revtstmp <= ?{code}
However, the {{revtstmp}} represents epoch _millis_, as can be seen [a few lines
up|https://github.com/hibernate/hibernate-orm/blob/6.2.7/hibernate-envers...]
in {{RevisionTimestampValueResolver.resolveNow(Object)}}:
{code:java}revisionTimestampSetter.set( object, System.currentTimeMillis() );{code}
As a result, {{AuditReader.getRevisionNumberForDate(LocalDateTime)}} will basically never
return anything if we have a {{@RevisionTimestamp long revtstmp}} attribute.
----
Workaround: Use {{AuditReader.getRevisionNumberForDate(Date)}}, where the
{{java.util.Date}} argument is correctly converted to epoch _millis_ in
{{RevisionTimestampValueResolver.resolveByValue(Date)}} [here|https://github.
com/hibernate/hibernate-orm/blob/6.2.7/hibernate-envers/src/main/java/org/hibernate/envers/internal/revisioninfo/RevisionTimestampValueResolver.java#L57].
(
https://hibernate.atlassian.net/browse/HHH-17080#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-17080#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100234- sha1:aec3a25 )