Uploaded image for project: 'Spring Data Commons'
  1. Spring Data Commons
  2. DATACMNS-1109

Allow any TemporalAccessor to be used as last modified date in auditing

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0 M4 (Kay)
    • Fix Version/s: 2.0 RC1 (Kay)
    • Component/s: Core
    • Labels:
      None

      Description

      This issue is a regression in 2.0 (it works correctly in 1.x). The org.springframework.data.domain.Auditable interface allows the getLastModifiedDate() method to return TemporalAccessor. However, if you actually do that, you get this exception at runtime:

      org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.time.Instant] to type [java.time.LocalDateTime]
      	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:979)
      	…
      Caused by: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.time.Instant] to type [java.time.LocalDateTime]
      	at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:319)
      	at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:192)
      	at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:173)
      	at org.springframework.data.auditing.DefaultAuditableBeanWrapperFactory$DateConvertingAuditableBeanWrapper.lambda$getAsTemporalAccessor$0(DefaultAuditableBeanWrapperFactory.java:219)
      	at java.util.Optional.map(Optional.java:215)
      	at org.springframework.data.auditing.DefaultAuditableBeanWrapperFactory$DateConvertingAuditableBeanWrapper.getAsTemporalAccessor(DefaultAuditableBeanWrapperFactory.java:219)
      	at org.springframework.data.auditing.MappingAuditableBeanWrapperFactory$MappingMetadataAuditableBeanWrapper.getLastModifiedDate(MappingAuditableBeanWrapperFactory.java:193)
      	at org.springframework.data.rest.webmvc.HttpHeadersPreparer.lambda$getLastModifiedInMilliseconds$4(HttpHeadersPreparer.java:119)
      	at java.util.Optional.flatMap(Optional.java:241)
      	at org.springframework.data.rest.webmvc.HttpHeadersPreparer.getLastModifiedInMilliseconds(HttpHeadersPreparer.java:119)
      	at org.springframework.data.rest.webmvc.HttpHeadersPreparer.prepareHeaders(HttpHeadersPreparer.java:80)
      	at org.springframework.data.rest.webmvc.ResourceStatus.getStatusAndHeaders(ResourceStatus.java:62)
      	at org.springframework.data.rest.webmvc.RepositoryEntityController.lambda$getItemResource$3(RepositoryEntityController.java:337)
      	at java.util.Optional.map(Optional.java:215)
      	at org.springframework.data.rest.webmvc.RepositoryEntityController.getItemResource(RepositoryEntityController.java:333)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:208)
      	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:135)
      	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:100)
      	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:859)
      	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:769)
      	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:86)
      	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:970)
      	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:904)
      	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:971)
      	... 105 more
      

      The problem was caused in this commit where MappingAuditableBeanWrapperFactory's getLastModifiedDate() method was changed to use LocalDateTime instead of TemporalAccessor (presumably by accident?)

        Attachments

          Activity

            People

            Assignee:
            olivergierke Oliver Drotbohm
            Reporter:
            candrews Craig
            Last updater:
            Oliver Drotbohm
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: