Building index and unique constraint for Mongo collection

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Unresolved
    • Priority: Trivial - P5
    • None
    • Affects Version/s: None
    • Component/s: Model
    • None
    • 5
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Compared to SQL databases, MongoDB is schema-less. The only DDL counterpart is MongoDB collection index and unique constraint creation.

      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:
            Unassigned
            Reporter:
            Nathan Xu (Inactive)
            None
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: