Kai Zander (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMjM1OWE5MWM0...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-17080?atlOrigin=eyJpIjoiMjM1OW...
) HHH-17080 (
https://hibernate.atlassian.net/browse/HHH-17080?atlOrigin=eyJpIjoiMjM1OW...
) [Envers] AuditReader.getRevisionNumberForDate(LocalDateTime) uses Epoch Seconds instead
of Epoch Millis (
https://hibernate.atlassian.net/browse/HHH-17080?atlOrigin=eyJpIjoiMjM1OW...
)
Issue Type: Bug Affects Versions: 6.2.7 Assignee: Chris Cranford (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) Components: hibernate-envers Created: 15/Aug/2023 00:59 AM Priority: Major Reporter: 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-envers/sr...
) :
return localDateTime.atZone( ZoneId.systemDefault()
).toInstant().getEpochSecond();
The result is then used as the parameter in the revision number query:
select max (rev) from revision_info where revtstmp <= ?
However, the revtstmp represents epoch millis , as can be seen a few lines up (
https://github.com/hibernate/hibernate-orm/blob/46d907deb1f15965c13ade81f...
) in RevisionTimestampValueResolver.resolveNow(Object) :
revisionTimestampSetter.set( object, System.currentTimeMillis() );
As a result, AuditRead.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).
(
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 )