Skip to content

MappingCouchbaseConverter skips ID field in read operation [DATACOUCH-27] #338

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
spring-projects-issues opened this issue Sep 16, 2013 · 3 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link

Maciej Zasada opened DATACOUCH-27 and commented

@Id annotated field is skipped by MappingCouchbaseConverter during convertion from CouchbaseDocument.

i.e. the following test will fail:

  @Test
  public void readsID() {
    // given:
    CouchbaseDocument converted = new CouchbaseDocument("001");

    // when:
    BasicCouchbasePersistentPropertyTests.Beer beer = converter.read(BasicCouchbasePersistentPropertyTests.Beer.class,
        converted);

    // then:
    assertEquals("001", beer.getId());
  }

IMO the problem lays in the following snippet:

 entity.doWithProperties(new PropertyHandler<CouchbasePersistentProperty>() {
      public void doWithPersistentProperty(final CouchbasePersistentProperty prop) {
        if (!source.containsKey(prop.getFieldName()) || entity.isConstructorArgument(prop)) {
          return;
        }

        Object obj = prop.isIdProperty() ? source.getId() : getValueInternal(prop, source, evaluator, result);
        wrapper.setProperty(prop, obj, useFieldAccessOnly);
      }
    });

Codition !source.containsKey(prop.getFieldName()) || entity.isConstructorArgument(prop) will be satisfied while processing @Id field, so it'll be skipped in the process


Affects: 1.0 M1

Referenced from: commits c4aa364, 8ade609, c62ad42, 0fa284e

@spring-projects-issues
Copy link
Author

Maciej Zasada commented

I've created pull request for this issue - the way we had fixed it

@spring-projects-issues
Copy link
Author

Michael Nitschinger commented

Thanks! I'm out for a week but get to it soon afterwards!

@spring-projects-issues
Copy link
Author

Michael Nitschinger commented

Thanks Maciej!

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

No branches or pull requests

2 participants