Java/Spring - id is null in sub-document

Hey,

We’re using the latest spring-boot-starter-data-couchbase dependency and java 11.
We have a @Document class called “Message” in with an id field and a List submessages field. The top-level message has a generated id (@GeneratedValue(strategy = GenerationStrategy.UNIQUE)). For sub-messages we generate the id manually before saving the top-level message to the database. I can see the id of the sub-messages using the couchbase webclient. But when the data is queried using a @Repository extending CouchbaseRepository<Message, String>, the submessages have null ids (with findById and also using a n1ql @Query).

// Message.java
@Document
public class Message implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationStrategy.UNIQUE)
    private String id;
    @Field
    private String channel;
    @Field
    private Date timestampCreated;
    @Field
    private List<Message> submessages;
    @Field
    private String content;
}

// MessageRepository.java

@Repository
public interface MessageRepository extends CouchbaseRepository<Message, String> {
	
    @Query("#{#n1ql.selectEntity} WHERE #{#n1ql.filter} AND channel = $1 ORDER BY timestampCreated limit $2 ")
    List<Message> getMessagesByChannel(String channel, Integer limit);
}

Example query result in the couchbase web ui for document with id 4be79ba6-3994-4198-a211-3a68cc320efa:

{
  "timestampCreated": 1632937100357,
  "channel": "b1452c43-aea4-4465-b657-a415e6565edd",
  "submessages": [
    {
      "timestampCreated": 1632937935858,
      "channel": "b1452c43-aea4-4465-b657-a415e6565edd",
      "id": "4be79ba6-3994-4198-a211-3a68cc320efa:0",
      "content": "Lorem-Sub"
    }
  ],
  "_class": "net.vaudience.chat.model.chat.Message",
  "content": "Lorem"
}

Example query result in java:

{
    "id": "4be79ba6-3994-4198-a211-3a68cc320efa",
    "channel": "b1452c43-aea4-4465-b657-a415e6565edd",
    "timestampCreated": 1632937100357,
    "submessages": [
      {
        "id": null,
        "channel": "b1452c43-aea4-4465-b657-a415e6565edd",
        "timestampCreated": 1632937935858,
        "submessages": null,
        "content": "Lorem-Sub"
      }
    ],
    "content": "Lorem"
}

What could cause the ids of the submessages to be null when querying the data in java/spring?

Cheers!

Looking at spring-data-couchbase, there doesn’t seem to be around this. MappinCouchbaseConverter::read does the mapping differently for id properties.
Object obj = prop.isIdProperty() ? source.getId() : MappingCouchbaseConverter.this.getValueInternal(prop, source, instance);

So I guess there is no way to have working IDs when having documents inside a document.

This was fixed in 4.2.3

Thanks for the info! Looks like our project is still on 4.1.3 (inherited by spring-boot-starter still being on version 2.4.2). Will try to upgrade and see if that works.