Skip to content
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

Improper identifier property detection on reading entity with annotated identifier property #4877

Closed
valer-crisan-sage opened this issue Jan 16, 2025 · 1 comment
Assignees
Labels
type: bug A general bug

Comments

@valer-crisan-sage
Copy link

The following scenario is not working as expected with version 4.4.1 - it was last working in version 4.3.7

We have an entity which contains a MongoDB "_id" field, an "id" field and other arbitrary fields. For example:

@Data
@Document(collection = "test")
public class MdbTest {
    @Id
    private String key;
    private String id;
    // ... other fields here
}

The find() operations in 4.4.1 are returning the data when filtering by the "id" field, but the value of the "id" field is always null.
In 4.3.7, the value of the "id" field is returned as expected.

Is this an intentional change in behavior?

Here is a small test replicating the scenario. The last assertion fails with version 4.4.1.

    MdbTest record = new MdbTest();
    record.setKey("123");
    record.setId("ID 123");
    Assertions.assertNotNull(record.getId());
    mongoTemplate.save(record);

    Query query = new Query(Criteria.where("id").is("ID 123"));
    record = mongoTemplate.findOne(query, MdbTest.class);
    Assertions.assertNotNull(record);

    Assertions.assertNotNull(record.getId());  // THE TEST FAILS HERE!
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 16, 2025
@christophstrobl
Copy link
Member

Thanks for reporting. We'll have a look.

@christophstrobl christophstrobl self-assigned this Jan 16, 2025
@christophstrobl christophstrobl added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 16, 2025
@mp911de mp911de changed the title The value for the field named "id" in DTO is null in version 4.4.1 Improper identifier property detection on reading entity with annotated identifier property Jan 16, 2025
@mp911de mp911de added this to the 4.4.2 (2024.1.2) milestone Jan 16, 2025
mp911de added a commit that referenced this issue Jan 16, 2025
Consistently use entity.isIdProperty(…) to determine whether a property is the identifier.

Original pull request: #4878
See #4877
mp911de pushed a commit that referenced this issue Jan 16, 2025
…exist.

We now check if a property identifies as the entities id property when populating values read from the source document.

Original pull request: #4878
Closes #4877
mp911de added a commit that referenced this issue Jan 16, 2025
Consistently use entity.isIdProperty(…) to determine whether a property is the identifier.

Original pull request: #4878
See #4877
mp911de pushed a commit that referenced this issue Jan 16, 2025
…exist.

We now check if a property identifies as the entities id property when populating values read from the source document.

Original pull request: #4878
Closes #4877
mp911de added a commit that referenced this issue Jan 16, 2025
Consistently use entity.isIdProperty(…) to determine whether a property is the identifier.

Original pull request: #4878
See #4877
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
4 participants