-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-18532 Date/time related JavaType's are not always properly unwrapping into java.util.Date subclasses #8833
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3e1249b
HHH-18532 Test cases checking that value is unwrapped to requested type
cigaly d6d7cf3
HHH-18532 Fixed two things:
cigaly 9a87812
HHH-18532 Suggested fix to conversion of epoch time in milliseconds t…
cigaly 670de92
HHH-18532 Using java.util.Calendar instead of java.time.* clases to c…
cigaly File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why you removed this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Request is that output
Timeshould represent local time on January 1st 1970, but it input can be on any date, for example:This the reason why we have to treat it like any other
java.util.DatesubclassThis is now
java.sql.Timeinstance on January 1st 1970There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get that, it's just unfortunate that we would have to create copies every time we bind a
java.sql.Timeto a prepared statement even if the value already is correctly at the epoch date.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is true. One possibility to prevent this is to return time if it is already at epoch date, and make new copy if not. Something like
Alternatively
java.util.Calendarcan be used, but I guess that this is 'cheaper' to createjava.util.Dateinstance thanjava.util.CalendarThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I'm missing something, but
java.util.Date#getTime()specifiesSo AFAIU, using the modulo trick that we have right now should work just fine. Please help me understand what I am missing. According so java docs the code should be correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getHours()is deprecated and the Java doc also explains that it returns the TZ dependent value.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct, that (and all other getXXX methods, with exception of getTime) were deprecated starting from JDK 1.1. Additional reason why
java.timeclasses should be used.Anyway, I see that you are using
Time.valueOf(LocalTIme)(seven out of eight times in hibernate-core), so here is one example ...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact,
java.sql.Time#valueOf(java.time.LocalTime)will interpret theLocalTimeas being a time in the time zone of the JVM, which is IMO natural given the wayjava.sql.Time#getTime()is specified. So to compute the milliseconds for that time since the epoch, it will have to add the time zone offset for the 1st January 1970, which is GMT-5, so it will have to add 18000000 milliseconds to get a GMT value.I don't know where
java.sql.Time#valueOf(java.time.LocalTime)is used in our code, but I agree that we have to be careful not to use that method if theLocalTimevalue comes from the database, because AFAIU that value would have no time zone association.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
org.hibernate.query.hql.internal.SemanticQueryBuilder#sqlTimeLiteralFromorg.hibernate.type.descriptor.java.JdbcTimeJavaType#wraporg.hibernate.type.descriptor.java.JdbcTimeJavaType#fromStringorg.hibernate.type.descriptor.java.JdbcTimeJavaType#fromEncodedStringorg.hibernate.type.descriptor.java.LocalTimeJavaType#unwraporg.hibernate.type.descriptor.java.OffsetTimeJavaType#unwrap`org.hibernate.type.descriptor.jdbc.TimeUtcAsJdbcTimeJdbcType#getBinder
Anyway as Yoggi Berra used to say, it's like déjà vu all over again, so I suggest that this PR be closed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to discourage you on your quest to fix time zone related issues, but we have to be careful to fully understand real problems before doing anything.
I'm sure there is a bug hiding somewhere, but it would be best if we first start off with a real use case that fails.