Skip to content

Spring Boot 4 LocalDate Projection No Longer Working #48570

@Banesword

Description

@Banesword

We have an application with a legacy Oracle database. It uses Spring Data Rest to access the tables directly as well as native query-based projections. We've run into an issue upgrading from Spring Boot 3.5.x to 4.0.0 with the projects that seem to be related to default type changes in Hibernate and Converter configuration in Spring itself.

The error we get when accessing a native query projection with a date in it is:

2025-12-17T12:49:16.833-07:00  WARN 28048 --- [           main] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Cannot project java.time.LocalDateTime to java.time.LocalDate; Target type is not an interface and no matching Converter found]

Hibernate changed the default Java types returned by native queries to use java.time based types (which we actually do prefer) but in this case is using a LocalDateTime, and we are using it as a LocalDate. It looks like there should be a converter for this, but for some reason it doesn't seem to be in the collection of converters used.

We can work around this issue using the hibernate.query.native.prefer_jdbc_datetime_types setting, configuring a @SqlResultSetMapping to control the type Hibernate is using, or using a @Value SPEL expression to perform the conversion ourselves, but we are trying to keep the application configured as "out-of-the-box" as possible and all of these workarounds seem like things that will break at some point going forward.

We tried registring our own LocalDateTime to LocalDate converter, but it's not clear how to actually register that in the collection of converters that are actually used in this case.

Including a demo project that shows the issue, and can be switched between Spring Boot 3.5.8 and 4.0.0 by changing the pom.xml file to 4.0.0 and commenting out the appropriate set of dependencies, and changing the import in DemoApplicationTests.java

converter-issue.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions