[#1904] LocalDateBasicUserType incorrectly converting to java.sql.Timestamp (Multiset fetching)
Description
- Changed fromString method to convert date/date time strings to a LocalDate instead of to a java.sql.Timestamp first
- Added a LocalDate field to DocumentForCollections entity and the MultiSet fetch view associated with said backing entity
- Updated multiset fetch test case to use the LocalDate to make sure exception is no longer thrown and test passes
Related Issue
Fixes #1904
Motivation and Context
Allows us to safely use a LocalDate in an entity view fetched using the Multiset fetch strategy without having to use a custom BasicUserType to override the behavior.
@beikov We can also do something like this to be compatible with someone using a datetime db type for a LocalDate. Lmk if you want me to change it to this
@Override
public LocalDate fromString(CharSequence sequence) {
String input = sequence.toString();
try {
return LocalDate.parse(input, DateTimeFormatter.ISO_LOCAL_DATE);
} catch (DateTimeParseException e) {
try {
LocalDateTime dateTime = LocalDateTime.parse(input, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
return dateTime.toLocalDate();
} catch (DateTimeParseException ex) {
throw new IllegalArgumentException("Invalid date or date-time format");
}
}
}
Could you please use construct a DateTimeFormatter as static variable, that has an optional time part?
Hi @dsarlo , since you have worked on this. can you please extend the same to OffsetDateTimeBasicUserType as well. There as well its same issue.
Once check this Thread, https://github.com/Blazebit/blaze-persistence/issues/1864#issuecomment-1916634538
cc : @beikov
Thanks y'all! I’ll take a look and will make the changes in a bit
@rajadilipkolli I do not see an issue with OffsetDateTimeBasicUserType. When using an OffsetDateTime in an entity view to trigger it, it's parsed correctly without issue. If you can provide some insight into the issue with it, I can take a better look
@beikov Changes pushed
Thanks for your work. I'll try to get this through the finish line as part of https://github.com/Blazebit/blaze-persistence/pull/1911