bguerout/jongo

Discuss : String id with @MongoId/@Id (only) not generated anymore since v1.2

Closed this issue · 6 comments

Hi,

I just migrated from jongo@1.0 to jongo@1.3.0 and noticed some changes in behaviour on POJOs looking like ExternalFriend.

I mean a POJO looking like

public class Foo {
    @Id @MongoId
    private String id;
}

In that case, I identified a behaviour change between jongo@1.1 and jongo@1.2 while calling collection.insert(myPojo) :

  • On jongo@1.1 and before : myPojo.getId() was filled with generated id
  • On jongo@1.2 onward (same behaviour actually on master) : myPojo.getId() was returning null

I didn't noticed such change tracked in the 1.2 release note and am wondering if this should be considered as a bug or as a "normal behaviour" (after all, we may consider that if @MongoObjectId annotation is missing, we should not expect an id generation ... but this rule was not applicable in versions <= 1.1)

FYI, you can reproduce this behaviour by adding following test in InsertTest which will pass on v <= 1.1 and not on v >= 1.2 :

    @Test
    public void canInsertPojoWithStringIdNotHavingObjectIdAnnotation() {
        ExternalFriend friend = ExternalFriend.createFriendWithoutId("John");
        collection.insert(friend);
        assertThat(friend.getId()).isNotEqualTo(null);
    }

PS: this issue sounds related to #269

@bguerout any idea about this behaviour ?

If this is an expected behaviour, I can close the issue.
I only want a confirmation from your side because I have some regression tests in restx which are based on this behaviour :-)

I put in a PR at some point to fix regressions with the ID behavior, I think between 1.0 and 1.1 1.1 and 1.2. This could be fall out from correcting that regression and we should make sure this situation does not cause flapping. I added a unit test to fully document the ID behavior. Let me dig it up that PR and test.

Here is the PR where work was done on the different ID annotations and what expected behavior should be for version 1.3. #274

This test documents what should happen with the different combinations of annotations and when mixins get involved. If you are seeing a gap, perhaps that test should be improved. https://github.com/bguerout/jongo/blob/master/src/test/java/org/jongo/marshall/jackson/IdSpecTest.java

confirmed behavior with v1.4.0

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.