Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spfeiffer24 opened this issue Jan 3, 2022 · 1 comment
Labels
status: duplicate A duplicate of another issue

Comments

@spfeiffer24
Copy link

spfeiffer24 commented Jan 3, 2022

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.

@sothawo sothawo added the status: duplicate A duplicate of another issue label Jan 3, 2022
@sothawo
Copy link
Collaborator

sothawo commented Jan 3, 2022

This is a duplicate of #2018, fixed by #2019 and will be contained in version 4.3.1. If you want to try this before the next maintenance release, you can use 4.3.1-SNAPSHOT from the snapshot repository (see the readme for details)

@sothawo sothawo closed this as completed Jan 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

2 participants