Auto-infer dialect and connection provider from MongoDB JDBC URL

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Configuration
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Currently, users must specify three configuration properties:

      hibernate.dialect=MongoDB
      hibernate.connection.provider_class=mongodb
      jakarta.persistence.jdbc.url=mongodb://localhost/mydb
      

      Since the dialect and connection provider always go together with a MongoDB URL, both can be inferred automatically, reducing the required configuration to:

      jakarta.persistence.jdbc.url=mongodb://localhost/mydb
      

      Proposed implementation

      Add inference logic to MongoStrategyContributor.contribute(), which is invoked for every Hibernate bootstrap before any service initiators run, making auto-applied settings visible to DialectFactory and ConnectionProviderInitiator when they subsequently run.

      Two inference rules, applied in order:

      1. If jakarta.persistence.jdbc.url starts with mongodb:// or mongodb+srv:// and hibernate.dialect is not set, auto-set hibernate.dialect=MongoDB.
      2. If hibernate.dialect=MongoDB (whether set explicitly or inferred from the URL) and hibernate.connection.provider_class is not set, auto-set hibernate.connection.provider_class=mongodb and register MongoConnectionProvider in the StrategySelector.

      Acceptance criteria

      • Setting only jakarta.persistence.jdbc.url=mongodb://... is sufficient to bootstrap without error.
      • Setting only hibernate.dialect=MongoDB (plus a URL) auto-selects the connection provider.
      • Explicit configuration of either setting is still respected and unchanged.
      • Non-MongoDB sessions are unaffected.

            Assignee:
            Jeffrey Yemin
            Reporter:
            Jeffrey Yemin
            None
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: