-
Notifications
You must be signed in to change notification settings - Fork 192
FindByXXX fails to work with field marked as Id #1321
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
Comments
Thanks. Roi told me of the issue and I was not able to reproduce it. Please provide everything needed to reproduce it - the implementation of FileHeader and the repository and the code that calls findByKey. btw - I believe you should be using the findById method which uses the kv API. It will be about 10x faster than the query API that findByKey uses. |
spring-data-couchbase does not store the @id property in the document. It stores it only as the document id and in a query can be referenced by meta( |
Please also provide the document that was to be retrieved. |
If there is a constructor that has a 'key' argument, and that argument is ignored in the constructor (i.e. because the id is @generated), then the 'key' field in the class will not be populated from meta().id on find operations, thus a subsequent findByKey(found.getKey()) will not return anything because getKey() returned null because it was not set in the constructor. |
Hi @mikereiche I understand from your comment there could be some explanations for this issue. Also wanted to clarify again that it did work before we switched to new spring data and defined collections. So here are the details, Please let us know if we need to implement some adjustment for it to work again. Thanks alot! |
There was a bug introduced in 4.3.0 when the entity is an abstract class. |
Okay thanks @mikereiche |
I reconstructed the classes as best I could by re-typing from the screenshots. It would have been convenient if the actual files were posted as text. |
Found the issue. It manifests when a derived query is on a collection and the 'id' field (or version or expiry) is in a predicate. Instead of being replaced by META(collection).id, it is replaced by META(bucket).id - and therefore does not match. Here is my CouchbaseEntity, FileHeader and FileHeader repository classes and my test case (below under the Code section). [The bug I mentioned above was that _class is not projected, but it does not affect this case as the repository is defined using the concrete class FileHeader and not the abstract class CouchbaseEntity ]
Code``` package org.springframework.data.couchbase.domain;import lombok.AllArgsConstructor; @DaTa
package org.springframework.data.couchbase.domain; import lombok.AllArgsConstructor; import javax.validation.constraints.NotNull; @document public enum UploadStatus { public enum FileType { public enum FileHeaderAnalysis { }
package org.springframework.data.couchbase.domain; import com.couchbase.client.java.query.QueryScanConsistency; @repository
@test
|
@mikereiche Thanks a lot for all the effort. |
Hi!

Before the upgrade to Spring Data 4.3 we had the following derived query working fine:
The find by was accessing this field with the name 'key' which is marked as Id by annotation and results were retrieves as expected.

(Please note: It worked without n1ql implementation)
Following the upgrade, derived methods which are approaching field marked with @id failed to retrieve results (Also with combination of another fields, For example: findByKeyAndStatus()).
We solved it using CrudRepository inherited method of findById()
But We would still like to understand what has changed that it's now fails to work? is it a bug?
Thanks.
The text was updated successfully, but these errors were encountered: