Uploaded image for project: 'Spring Data MongoDB'
  1. Spring Data MongoDB
  2. DATAMONGO-525

Customizable naming strategy for auto mapping domain object to database names

    Details

    • Type: New Feature
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      As a developer, I would like to be able to set a naming strategy that can automatically convert my field and entity names inside my domain object to the format expected of the database. This will avoid unnecessary coupling of database details (i.e. the name of the table or column) to the domain object and avoid having to annotate every field in the domain object. This sort of functionality is similar to Hibernate's NamingStrategy interface (https://docs.jboss.org/hibernate/orm/4.0/javadocs/org/hibernate/cfg/NamingStrategy.html) except it would work for any type of database (in our case MongoDB).

      @Document(collection = "my_account")
      public class MyAccount {
      	@Id
      	private ObjectId id;
      
      	private String name;
      
      	@Field("customer_id")
      	private ObjectId customerId;
      }
      

      In this example, the database document and fields expect the name to be lowercase with underscores but our domain object uses standard Java camelCase. If there was a naming strategy that automatically converted all camelCase fields or document names to underscores then we could avoid the @Field annotation and specifying the collection name. If any field needed a custom name that differed from the naming strategy, it could still be overridden with @Field.

        Attachments

          Activity

            People

            • Assignee:
              olivergierke Oliver Gierke
              Reporter:
              ssheehy Steven Sheehy
              Last updater:
              Ankur Pathak
            • Votes:
              6 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: