Custom Naming Strategies for collections MongoDB #1933
-
|
Hi, Is there any configurable way to create custom Naming Strategies for collections, and set in annotation @MappedEntity in micronaut-data-mongodb? I'm creating a custom class that implements NamingStrategy interface, but the collection is created using the default strategy anyway. My attempt below: Naming Custom Strategy My Entity |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
"Since Micronaut Data pre-computes the table and column name mappings at compilation time the specified NamingStrategy implementation must be on the annotation processor classpath (annotationProcessor scope for Java or kapt for Kotlin)." |
Beta Was this translation helpful? Give feedback.
-
|
@lacerdanycolas One issue I had with this is that first needed to add my custom NamingStrategy, build project so libs are available for the annotation processor and then add this ^ to build.gradle HTH, |
Beta Was this translation helpful? Give feedback.
@lacerdanycolas
Here is an simple example I created using Micronaut Launch: https://github.com/radovanradic/demo-mongo-ns
I have noticed you are using Kotlin so this is what should be added for annotation processor:
One issue I had with this is that first needed to add my custom NamingStrategy, build project so libs are available for the annotation processor and then add this ^ to build.gradle
There is probably better way but I am not very experienced with the build so this was workaround for me. You can see in debug logs when running test that Mongo is creating collection using custom naming strategy.
HTH,
Radovan