Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autogenerate id in Cosmos DB from Spring Boot

How can I generate an autoincremented Id in a Cosmos DB if I do a POST request from Spring Boot.

like image 869
Techie Avatar asked Oct 27 '25 04:10

Techie


2 Answers

The docs explain the behavior here: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/spring/azure-spring-data-cosmos/README.md

public class GeneratedIdEntity {

    @Id
    @GeneratedValue
    private String id;
}

As mentioned, Cosmos uses UUIDs rather than an auto-increment long.

like image 179
avolkmann Avatar answered Oct 28 '25 20:10

avolkmann


Use @Id @GeneratedValue private String id;

like image 44
Leonardo Vargas Trigueros Avatar answered Oct 28 '25 20:10

Leonardo Vargas Trigueros