Create collections and build indexes and unique constraints for collection

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Fixed
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Model
    • None
    • 5
    • None
    • Needed
    • None
    • None
    • None
    • None
    • None
    • None

      Compared to SQL databases, MongoDB is schema-flexible. The only DDL counterpart is MongoDB collections themselves, the collection index and unique constraint creation (though MongoDB also supports JSON schemas).

      We need to implement the applicable schema tool Hibernate settings from org.hibernate.cfg.SchemaToolingSettings, e.g.:

      jakarta.persistence.schema-generation.database.action

      to either create or drop indexes and unique constraints based on entity class annotations:

      @Entity(name = "Book")
      @Table(
              name = "books",
              indexes = {
                  @Index(name = "idx_on_single_col", columnList = "publishYear"),
                  @Index(name = "idx_on_multi_cols", columnList = "publisher,author"),
                  @Index(name = "uniq_idx_on_single_col", columnList = "isbn", unique = true),
                  @Index(name = "uniq_idx_on_multi_cols", columnList = "publisher,title", unique = true)
              }
      )
      class Book {
          @Id @GeneratedValue UUID id;
          String isbn;
          String author;
          String title;
          String publisher;
          int publishYear;
      }
      

      A POC implementation is at https://github.com/NathanQingyangXu/jpa-mongodb-mapping/tree/main/chameleon-core/src/test/java/org/hibernate/omm/index

      Addressing the source code notes tagged with TODO-HIBERNATE-66 is in scope of this ticket.

            Assignee:
            Andre Masella
            Reporter:
            Nathan Xu (Inactive)
            Jeffrey Yemin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: