-
Notifications
You must be signed in to change notification settings - Fork 190
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
Following DTO Projection doc #1543
Comments
Looks like as() is being passed a null.
It would be helpful to see |
Also :
I'm not sure about OnetoOne. |
Just a simple service : @Service
class PersonService(
private val repository: PersonRepository
) {
fun createPerson(person: Person) = repository.save(person)
fun getProjectionByName(name: String) = repository.findByName(name)
} I updated my dummy repository on https://github.com/rbleuse/spring-reactive-couchbase/tree/projection (branch |
edit: getTypeToRead() is returning null even though it has enough information to determine the return type. I'm still investigating.
As a work-around when only one simple property is being returned (in your case Name contains only a String), the method can be defined to return that simple time and it will work
|
Name needs to be a class. This will suffice:
It seems that some better diagnostics would help. |
Thanks, indeed with a class it's working. However I tried to proceed to the same with a custom n1ql instead of using the method name, but I faced this exception : interface PersonRepository : ReactiveCouchbaseRepository<Person, String> {
@Query("select p.firstName, p.lastName from #{#n1ql.bucket} p WHERE p.firstName = '#{[0]}' AND p.#{#n1ql.filter}")
fun findByFirstName(firstName: String): Flux<PersonName>
} @Document
@Scope("dev")
@Collection("person")
data class Person(
@field:Id
val id: String,
@field:Field
val firstName: String,
@field:Field
val lastName: String
) data class PersonName(val firstName: String, val lastName: String) stack trace
So it seems with a custom query we have to query the document id as well ? |
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 : #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. |
Oh understood, so under the hood And for a manual custom query projection, I also need to add an Indeed it's working as expected if I don't declare it in my projection dto as long as I add the id in my query. Thank you ! |
Or you could just use the newer version that doesn't require it. |
Which newer version are you referring to ? I'm using 4.4.2 and it's still required with latest 4.4.3-SNAPSHOT
|
My mistake - the id is always required when anything other than one simple field is projected. So just project "" as __id. |
Hello,
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 :
Projection interface :
Person repository :
Exception :
Is the documentation is up to date, and can we use projection with spring data couchbase ?
The text was updated successfully, but these errors were encountered: