I'm dumping some data into my MongoDb and generate a UUID on the way. In the collection, this UUID field is stored as LUUID (legacy UUID - type 3) and I don't know how to avoid this, because I would want the format to be the standard UUID (type 4).
Entity:
@Document(collection = "sms")
public class SmsEntity {
...
private UUID ubmMessageSid; // <- this field gets stored as LUUID
...
public static class Builder {
...
private UUID ubmMessageSid;
...
public Builder ubmMessageSid(UUID ubmMessageSid) {
this.ubmMessageSid = ubmMessageSid;
return this;
}
public SmsEntity build() {return new SmsEntity(this);}
}
}
Repo:
@Repository
public interface SmsRepository extends CrudRepository<SmsEntity, String> {
}
Service storing this entity:
...
var ubmId = UUID.randomUUID();
var smsEntity = SmsEntity.builder()
.ubmMessageSid(ubmId)
...
.build();
repository.save(smsEntity);
Anything I have to annotate or configure to store the UUID as Binary/type4?
In Spring Boot 2, for Spring MongoDB 3.x, you can set this using the autoconfiguration properties:
# Options: unspecified, standard, c_sharp_legacy, java_legacy, python_legacy
spring.data.mongodb.uuid-representation=standard
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With