Skip to content

Spring Data Elasticsearch 4.3.0 (Spring Boot 2.6.2): ClassCastException String -> Date in generated Query with Date #2048

Closed
@spfeiffer24

Description

@spfeiffer24

Demo: https://github.com/spfeiffer24/spring-data-es-issue-demo

The generated query in DemoEventRepository with the date parameter works in Spring Boot 2.5.8 (Spring Data ES 4.2.7) but in Spring Boot 2.6.2 (Spring Data ES 4.3.0) throws
Caused by: org.springframework.data.elasticsearch.core.convert.ConversionException: Unable to convert value '2022-01-03T17:06:00.985Z' of property 'timestamp' at org.springframework.data.elasticsearch.core.convert.DatePropertyValueConverter.write(DatePropertyValueConverter.java:65) ~[spring-data-elasticsearch-4.3.0.jar:4.3.0] at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.lambda$updateCriteria$1(MappingElasticsearchConverter.java:1266) ~[spring-data-elasticsearch-4.3.0.jar:4.3.0] at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na] at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1085) ~[na:na] at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.updateCriteria(MappingElasticsearchConverter.java:1258) ~[spring-data-elasticsearch-4.3.0.jar:4.3.0] at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.updateCriteriaQuery(MappingElasticsearchConverter.java:1193) ~[spring-data-elasticsearch-4.3.0.jar:4.3.0] at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.updateQuery(MappingElasticsearchConverter.java:1139) ~[spring-data-elasticsearch-4.3.0.jar:4.3.0] at org.springframework.data.elasticsearch.core.RequestFactory.searchRequest(RequestFactory.java:901) ~[spring-data-elasticsearch-4.3.0.jar:4.3.0] at org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate.count(ElasticsearchRestTemplate.java:305) ~[spring-data-elasticsearch-4.3.0.jar:4.3.0] at org.springframework.data.elasticsearch.repository.query.ElasticsearchPartQuery.execute(ElasticsearchPartQuery.java:113) ~[spring-data-elasticsearch-4.3.0.jar:4.3.0] at org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:137) ~[spring-data-commons-2.6.0.jar:2.6.0] at org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke(RepositoryMethodInvoker.java:121) ~[spring-data-commons-2.6.0.jar:2.6.0] at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:159) ~[spring-data-commons-2.6.0.jar:2.6.0] at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:138) ~[spring-data-commons-2.6.0.jar:2.6.0] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.14.jar:5.3.14] at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97) ~[spring-aop-5.3.14.jar:5.3.14] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.14.jar:5.3.14] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.14.jar:5.3.14] at com.sun.proxy.$Proxy46.findByTimestampAfter(Unknown Source) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.3.14.jar:5.3.14] at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.3.14.jar:5.3.14] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.14.jar:5.3.14] at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137) ~[spring-tx-5.3.14.jar:5.3.14] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.14.jar:5.3.14] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.14.jar:5.3.14] at com.sun.proxy.$Proxy46.findByTimestampAfter(Unknown Source) ~[na:na] at com.example.demo.DemoApplication.run(DemoApplication.java:30) ~[classes/:na] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:758) ~[spring-boot-2.6.2.jar:2.6.2] ... 5 common frames omitted Caused by: java.lang.ClassCastException: class java.lang.String cannot be cast to class java.util.Date (java.lang.String and java.util.Date are in module java.base of loader 'bootstrap') at org.springframework.data.elasticsearch.core.convert.DatePropertyValueConverter.write(DatePropertyValueConverter.java:62) ~[spring-data-elasticsearch-4.3.0.jar:4.3.0] ... 36 common frames omitted

Expected behaviour: Returns entity (like in Spring Boot 2.5.8)
Observed behaviour: Throws exception, does not start up

Verify using the demo project by changing Spring Boot version from 2.6.2 to 2.5.8 -> Exception does not occur anymore, entity is returned and its @Id printed to stdout.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions