Skip to content
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

Repository query projection not working as expected since 3.4.x #4524

Closed
jcedenopyx opened this issue Oct 9, 2023 · 3 comments
Closed

Repository query projection not working as expected since 3.4.x #4524

jcedenopyx opened this issue Oct 9, 2023 · 3 comments
Assignees
Labels
type: bug A general bug

Comments

@jcedenopyx
Copy link

When using a MongoRepository<A, B>, query functions that project from type A to type C (with compatible fields), spring attempts to convert the full object to the Id field type.

This behavior worked fine until spring data 3.3.x. Using @Id or @MongoId on the Id field has no effect, but using @Field("_id") makes it so that it maps properly.

Demo reproducing the bug: https://github.com/jcedenopyx/spring-data-mongo-query-projection-issue/blob/master/src/test/java/me/jcedeno/demo/DemoApplicationTests.java#L89-L95

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [me.jcedeno.demo.models.Transaction] to type [me.jcedeno.demo.models.TransactionId]
	at app//org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:322)
	at app//org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:195)
	at app//org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:175)
	at app//org.springframework.data.mapping.model.ConvertingPropertyAccessor.convertIfNecessary(ConvertingPropertyAccessor.java:121)
	at app//org.springframework.data.mapping.model.ConvertingPropertyAccessor.setProperty(ConvertingPropertyAccessor.java:64)
	at app//org.springframework.data.mongodb.core.convert.MappingMongoConverter.readAndPopulateIdentifier(MappingMongoConverter.java:574)
	at app//org.springframework.data.mongodb.core.convert.MappingMongoConverter.populateProperties(MappingMongoConverter.java:541)
	at app//org.springframework.data.mongodb.core.convert.MappingMongoConverter.doReadProjection(MappingMongoConverter.java:377)
	at app//org.springframework.data.mongodb.core.convert.MappingMongoConverter.project(MappingMongoConverter.java:323)
	at app//org.springframework.data.mongodb.core.MongoTemplate$ProjectingReadCallback.doWith(MongoTemplate.java:3348)
	at app//org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:2959)
	at app//org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:2676)
	at app//org.springframework.data.mongodb.core.ExecutableFindOperationSupport$ExecutableFindSupport.doFind(ExecutableFindOperationSupport.java:220)
	at app//org.springframework.data.mongodb.core.ExecutableFindOperationSupport$ExecutableFindSupport.all(ExecutableFindOperationSupport.java:163)
	at app//org.springframework.data.mongodb.repository.query.AbstractMongoQuery.lambda$getExecution$3(AbstractMongoQuery.java:178)
	at app//org.springframework.data.mongodb.repository.query.AbstractMongoQuery.doExecute(AbstractMongoQuery.java:152)
	at app//org.springframework.data.mongodb.repository.query.AbstractMongoQuery.execute(AbstractMongoQuery.java:127)
	at app//org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:137)
	at app//org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke(RepositoryMethodInvoker.java:121)
	at app//org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:160)
	at app//org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:139)
	at app//org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at app//org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:76)
	at app//org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at app//org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
	at app//org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at app//org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:241) 
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 9, 2023
@christophstrobl christophstrobl self-assigned this Oct 10, 2023
@christophstrobl
Copy link
Member

Thanks for reporting and the reproducer. We'll have a look.

@christophstrobl christophstrobl added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 10, 2023
@jcedenopyx jcedenopyx changed the title Repository query not working since 3.4.x Repository query projection not working as expected since 3.4.x Oct 10, 2023
mp911de pushed a commit that referenced this issue Oct 11, 2023
Contextual information required for converting values are now passed on correctly when projecting id properties.

Closes: #4524
Original pull request: #4525
mp911de pushed a commit that referenced this issue Oct 11, 2023
Contextual information required for converting values are now passed on correctly when projecting id properties.

Closes: #4524
Original pull request: #4525
mp911de pushed a commit that referenced this issue Oct 11, 2023
Contextual information required for converting values are now passed on correctly when projecting id properties.

Closes: #4524
Original pull request: #4525
@jcedenopyx
Copy link
Author

Thanks for fixing this so quick! Is this going out on October 13th?

@christophstrobl
Copy link
Member

@jcedenopyx with the next release, yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants