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

Fix coerce to date #308

Merged
merged 1 commit into from
Aug 17, 2016
Merged

Fix coerce to date #308

merged 1 commit into from
Aug 17, 2016

Conversation

xiaoyao1991
Copy link
Contributor

No description provided.

@yahoocla
Copy link

CLA is valid!

@xiaoyao1991
Copy link
Contributor Author

This should fix #292

@DennisMcWherter
Copy link
Collaborator

LGTM. Should we add an integration test to make sure this doesn't get mangled somewhere else?

@DennisMcWherter
Copy link
Collaborator

👍

@DennisMcWherter DennisMcWherter merged commit 39acb9a into master Aug 17, 2016
@DennisMcWherter DennisMcWherter deleted the fix_coerce_to_date branch August 17, 2016 15:45
@xiaoyao1991
Copy link
Contributor Author

xiaoyao1991 commented Aug 18, 2016

@DeathByTape As I was adding the integration tests, more problem reveals. Turns out I can construct a date from long, but when it is serialized through hibernate, the value stored in db will carry an implicit timezone. For example, for timestamp 1454638927412 (2016-02-05 02:22:07 GMT), when I construct a java.util.Date out of it and store it in db, it will be cast with my local timezone and become 2016-02-04, 20:22:07. The consequence of it will be: if I query the object by its original timestamp, this row will never return.

@@ -70,6 +74,9 @@ public Converter lookup(Class<?> sourceType, Class<?> targetType) {
return TO_ENUM_CONVERTER;
} else if (Map.class.isAssignableFrom(sourceType)) {
return FROM_MAP_CONVERTER;
} else if ((String.class.isAssignableFrom(sourceType) || Long.class.isAssignableFrom(sourceType))
Copy link
Contributor

@Koka Koka Sep 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xiaoyao1991 @DeathByTape I've found a bug here. If you try to create entity with date field and set value to 1970-01-01 (timestamp is -14400000 in my time zone) it will be automactically converted into Integer object, not Long inside elide because the value is too small and it seems like the smallest allowed number type is selected on conversion. Then it will miss this if branch and wrong date converter will be chosen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants