blaze-persistence icon indicating copy to clipboard operation
blaze-persistence copied to clipboard

[#1904] LocalDateBasicUserType incorrectly converting to java.sql.Timestamp (Multiset fetching)

Open dsarlo opened this issue 1 year ago • 5 comments

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.

dsarlo avatar May 16 '24 18:05 dsarlo

@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");
            }
        }
    }

dsarlo avatar May 16 '24 21:05 dsarlo

Could you please use construct a DateTimeFormatter as static variable, that has an optional time part?

beikov avatar May 17 '24 06:05 beikov

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

rajadilipkolli avatar May 17 '24 09:05 rajadilipkolli

Thanks y'all! I’ll take a look and will make the changes in a bit

dsarlo avatar May 17 '24 13:05 dsarlo

@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

dsarlo avatar May 17 '24 19:05 dsarlo

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

beikov avatar Jun 05 '24 19:06 beikov