I want to use UUID
instead of the plain String
value for fields annotated with @Id
, for example:
@Data // Lombok
public class Role {
@Id
private UUID id;
@Size(max = 18)
private String name;
}
However, inserting such object leads to Cannot autogenerate id of type java.util.UUID for entity of type Role
exception.
For reference, I've tried the following custom configuration with no success:
@Configuration
public class DatabaseConfiguration extends AbstractReactiveMongoConfiguration {
@Override
protected String getDatabaseName() {
return "test";
}
@Override
public void configureClientSettings(MongoClientSettings.Builder builder) {
builder.uuidRepresentation(UuidRepresentation.STANDARD); // <---
}
}
Are there any approaches to make it work WITHOUT creating custom AbstractMongoEventListener
per each model (creating one for the base class does not work either)?