Skip to content

"id" as field name getting populated with meta().id in the response #1258

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
balaji-it opened this issue Oct 18, 2021 · 4 comments · Fixed by #1261
Closed

"id" as field name getting populated with meta().id in the response #1258

balaji-it opened this issue Oct 18, 2021 · 4 comments · Fixed by #1261
Assignees
Labels
status: feedback-provided Feedback has been provided

Comments

@balaji-it
Copy link

balaji-it commented Oct 18, 2021

The documents having "id as field name not getting populated with the correct value in the response via spring-data Couchbase.
The stored value for id field is getting replaced with document meta().id when we fetch data using the query below.

@query("SELECT * FROM #{#n1ql.bucket} WHERE id = $1")

Example:
Below is the Document data stored in Couchbase: (meta().id => c00994b8-b547-4388-a549-e1543edbd9c8)
{
"id": "eeb7afa9-3ada-483d-ac1a-7efcf6e7b232",
“name”: “John”
}

Response object retrieved via NQL query above:
{
"id": "c00994b8-b547-4388-a549-e1543edbd9c8",
“name”: “John”
}

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 18, 2021
@mikereiche
Copy link
Collaborator

mikereiche commented Oct 18, 2021

Please include the entity class and the repository class in the issue.
Why is there no _class property in the document?
How(and why) was the document created with a different id than the meta().id?

@mikereiche
Copy link
Collaborator

The response is correct as that's what the decoder does - return meta().id of the document in the @id field (or the field named 'id' if there is no other field annotated with @id).
The question is - how was that document inserted - with the meta().id being different from the @id field?
spring-data-couchbase does not even store the @id field in the document (as it is already stored as meta().id and there is no need to duplicate it).

@mikereiche mikereiche added status: feedback-provided Feedback has been provided and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 19, 2021
@mikereiche
Copy link
Collaborator

If the issue persists with documents inserted using spring-data-couchbase, please reopen.

@mikereiche mikereiche self-assigned this Oct 19, 2021
@mikereiche mikereiche reopened this Oct 21, 2021
@mikereiche
Copy link
Collaborator

See CBSE-10927

The issue is that decode uses property.isIdProperty() to determine if a field is the id field. It should use property == entity.getIdProperty(). This is the check that should be use everywhere instead of property.isIdPropery().

Also StringBasedN1qlParser.getProjectedFieldsInternal() needs to use property = entity.getIdProperty() otherwise it will not project the field name id that is not an IdProperty.

@mikereiche mikereiche added this to the 4.3 GA (2021.1.0) milestone Oct 21, 2021
mikereiche added a commit that referenced this issue Oct 21, 2021
mikereiche added a commit that referenced this issue Oct 21, 2021
mikereiche added a commit that referenced this issue Oct 21, 2021
mikereiche added a commit that referenced this issue Oct 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-provided Feedback has been provided
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants