Skip to content

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

Closed
@spring-projects-issues

Description

@spring-projects-issues

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions