Search code examples
spring-data-couchbase

@Id and @Field on same variable?


Is there a way to achieve @Id and @Field on the same variable of a @Document so the variable is also saved inside the document? I'm trying to preserve the data I'm importing as much as I can, even though I get the design practices followed by the developers.


Solution

  • The @Id annotation will take priority over @Field, so no the id cannot be persisted as both document ID and value inside the document. Quickest way to achieve that is probably to duplicate the id field as a separate @Field annotated attribute?