Closed MapFilterMagic closed 1 year ago
It appears that placing a @JsonInclude(Include.ALWAYS)
on the _etag
field on the model resolves the error. Can anyone confirm that doing this won't mess with optimistic concurrency enforcement?
import org.springframework.data.annotation.Version;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.azure.spring.data.cosmos.core.mapping.Container;
@JsonInclude(Include.NON_EMPTY)
@Container(containerName = "my-container")
public class ExampleEntity implements PersistenceEntity {
@Id
private String id;
@JsonInclude(Include.ALWAYS)
@Version
private String _etag;
...
}
@MapFilterMagic - this repo has been retired and out of support for a long time now, see this - https://github.com/microsoft/spring-data-cosmosdb/blob/master/README.md
Please create a new issue on the current repo for azure-spring-data-cosmos project - https://github.com/Azure/azure-sdk-for-java/issues
Description
My team is attempting to set the
id
field on a document and are running into aNullPointerException
from theReactiveCosmosTemplate
when saving the document off to the DB. We're utilizing optimistic concurrency with the use of@Version
on an_etag
field. Up until now, we had left theid
field on the model unset, so Cosmos was just generating a random GUID for us. However, we now need to set this to a different unique value at the SDK level before saving it off into the database.What we've found is that we cannot have all of the following at the same time without running into that
NullPointerException
@Version
on an_etag
field@JsonInclude(Include.NON_EMPTY)
on our persisted modelid
field from the SDK level (in our code) instead of leaving it unset and having Cosmos generate it for usEliminating any one of those three resolves the error.
This appears to be the exact same issue we're running into except it was for the Azure Java SDK, and it involved
@JsonInclude(Include.NON_NULL)
(though theNON_EMPTY
is very close to the same thing). However, it appears they were closed?:Am I understanding that correctly?
Intended Resolution
Does anyone see a path forward? Do we know what the resolution of the issue(s) was, or if it could be looked at again? We're not in an immediate position to bump our Java version and jump to a higher version of Spring Boot/Spring Azure Cosmos DB SDK. We'd like to be able to use all three of the listed items at the same time.
The Error
Code Snippets
Our Data Model
Our Dao Layer
Our Repository Layer
Setup