Following DTO Projection doc
See original GitHub issueHello,
I was following the DTO Projection documentation but can’t make it work.
My set up : spring-boot 2.7.3 (data couchbase 4.4.2)
First, this documentation has example using spring data JPA (@Entity
and @OneToOne
annotations). Is it normal ?
Second, here is my simple test and the exception I get :
Person document :
@Document
@Scope("dev")
@Collection("person")
data class Person(
@field:Id
val id: String,
@field:Field
val name: String
)
Projection interface :
interface Name {
fun getName(): String
}
Person repository :
interface PersonRepository : ReactiveCouchbaseRepository<Person, String> {
fun findByName(name: String): Flux<Name>
}
Exception :
java.lang.IllegalArgumentException: returnType must not be null!
at org.springframework.util.Assert.notNull(Assert.java:201) ~[spring-core-5.3.22.jar:5.3.22]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
*__checkpoint ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter [DefaultWebFilterChain]
*__checkpoint ⇢ HTTP POST "/person" [ExceptionHandlingWebHandler]
Original Stack Trace:
at org.springframework.util.Assert.notNull(Assert.java:201) ~[spring-core-5.3.22.jar:5.3.22]
at org.springframework.data.couchbase.core.ReactiveFindByQueryOperationSupport$ReactiveFindByQuerySupport.as(ReactiveFindByQueryOperationSupport.java:134) ~[spring-data-couchbase-4.4.2.jar:4.4.2]
at org.springframework.data.couchbase.repository.query.AbstractReactiveCouchbaseQuery.lambda$getExecutionToWrap$1(AbstractReactiveCouchbaseQuery.java:122) ~[spring-data-couchbase-4.4.2.jar:4.4.2]
at org.springframework.data.couchbase.repository.query.ReactiveCouchbaseQueryExecution$ResultProcessingExecution.execute(ReactiveCouchbaseQueryExecution.java:77) ~[spring-data-couchbase-4.4.2.jar:4.4.2]
at org.springframework.data.couchbase.repository.query.AbstractReactiveCouchbaseQuery.doExecute(AbstractReactiveCouchbaseQuery.java:91) ~[spring-data-couchbase-4.4.2.jar:4.4.2]
at org.springframework.data.couchbase.repository.query.AbstractCouchbaseQueryBase.execute(AbstractCouchbaseQueryBase.java:133) ~[spring-data-couchbase-4.4.2.jar:4.4.2]
at org.springframework.data.couchbase.repository.query.AbstractCouchbaseQueryBase.execute(AbstractCouchbaseQueryBase.java:113) ~[spring-data-couchbase-4.4.2.jar:4.4.2]
at org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:137) ~[spring-data-commons-2.7.2.jar:2.7.2]
at org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke(RepositoryMethodInvoker.java:121) ~[spring-data-commons-2.7.2.jar:2.7.2]
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:160) ~[spring-data-commons-2.7.2.jar:2.7.2]
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:139) ~[spring-data-commons-2.7.2.jar:2.7.2]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.22.jar:5.3.22]
at org.springframework.data.couchbase.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:141) ~[spring-data-couchbase-4.4.2.jar:4.4.2]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.22.jar:5.3.22]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97) ~[spring-aop-5.3.22.jar:5.3.22]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.22.jar:5.3.22]
at org.springframework.data.repository.core.support.MethodInvocationValidator.invoke(MethodInvocationValidator.java:99) ~[spring-data-commons-2.7.2.jar:2.7.2]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.22.jar:5.3.22]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.22.jar:5.3.22]
at jdk.proxy2/jdk.proxy2.$Proxy101.findByName(Unknown Source) ~[na:na]
at com.rbleuse.spring.reactive.couchbase.service.PersonService.getProjectionByName(PersonService.kt:13) ~[main/:na]
Is the documentation is up to date, and can we use projection with spring data couchbase ?
Issue Analytics
- State:
- Created a year ago
- Comments:11 (4 by maintainers)
Top Results From Across the Web
Spring Data: when use Projection interfaces and DTO ...
Another way of defining projections is by using value type DTOs (Data Transfer Objects) that hold properties for the fields that are supposed...
Read more >Why, When and How to Use DTO Projections with JPA and ...
Using DTO projections with JPA and Hibernate. After you defined your DTO class, you can use it as a projection with JPQL, criteria...
Read more >Spring Data Commons - Reference Documentation
Closed Projections. A projection interface whose accessor methods all match properties of the target aggregate is considered to be a closed ...
Read more >The best way to fetch a Spring Data JPA DTO Projection
A DTO projection is a Java Object that contains the column values that were fetched by a given SQL projection query. The DTO...
Read more >Spring Data JPA Projections - 5 ways to return custom response
There may be cases where we do not want an entire entity from the query method. We may be interested only in few...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
My mistake - the id is always required when anything other than one simple field is projected. So just project “” as __id.
Yes. An id is(was) always expected for an entity. Also cas. It doesn’t matter what it is though. You can have “” as __id, 0 as __cas.
There is a change to only require __id and __cas if they are needed : https://github.com/spring-projects/spring-data-couchbase/issues/1402
That shows commits in main (May 3), 4.4.x (May 9) and 4.3.x (May 11). So it will be in the releases of those which occurred after (June 20 and July 15) https://calendar.spring.io/. July 15 shows 2021.1.6 -> 4.3.6, 2021.2.2 -> 4.4.2 and 2022.0.0 -> 5.0.0-M5.