我有 crudRepository 接口和名为 findLastUpdatedTimeByName 的方法:
public interface FooRepository extends CrudRepository<Foo, UUID> {
@Query(
"SELECT foo.last_updated_time FROM foo WHERE foo.name = :name")
Optional<OffsetDateTime> findLastUpdatedTimeByName(
@Param("name") Name name);
...
当我有 Spring Boot 2.5.7 版时,一切正常。但是在将 Spring Boot 更新到 2.6.3 版之后,当调用 findLastUpdatedTimeByName 方法时出现异常:
org.springframework.data.mapping.MappingException: Couldn't find PersistentEntity for type class java.time.OffsetDateTime!
at org.springframework.data.mapping.context.MappingContext.getRequiredPersistentEntity(MappingContext.java:79)
at org.springframework.data.relational.repository.query.DtoInstantiatingConverter.<init>(DtoInstantiatingConverter.java:61)
at org.springframework.data.jdbc.repository.query.JdbcQueryExecution$ResultProcessingConverter.lambda$new$0(JdbcQueryExecution.java:66)
at org.springframework.data.util.Lazy.getNullable(Lazy.java:230)
at org.springframework.data.util.Lazy.get(Lazy.java:114)
at org.springframework.data.jdbc.repository.query.JdbcQueryExecution$ResultProcessingConverter.convert(JdbcQueryExecution.java:84)
at org.springframework.data.jdbc.repository.query.AbstractJdbcQuery$ConvertingRowMapper.mapRow(AbstractJdbcQuery.java:187)
at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:94)
想不通,好像有什么问题。你们有什么想法吗?
编辑:我发现只有当查询结果为空时才会出现这个问题。但由于某种原因,spring 无法将其映射到 Optional.empty()