ObjectId type mapping

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Done
    • Priority: Major - P3
    • None
    • Java Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      The first ticket to map Bson-specific Java type to MongoDB data type, with JDBC type as the intermediary.

      Ideally an elegant and extensible way is to be found so in the future other Bson type mapping would boil down to some pattern repetition.

       

      The goal is to map the id field with org.bson.types.ObjectId type in the following entity class as expected:

       

      import org.bson.types.ObjectId;
      
      @Entity
      @Table(name = "books")
      class Book {
      
          @Id
          ObjectId id;
      
          ... ...
      }

       

      For instance, the following insertion processing

      sessionFactory.inTransaction(session -> {
          var book = new Book();
          book.id = ObjectId.get();
          ... ...
          session.persist(book);
      });

      might end up with the following MQL issued:

      {"insert": "books", "documents": [{..., "_id": {"$oid": "67d485d19faedd225f55b64e"}}]} 

       

      Complete CRUD integration testings are desired (loading by primary key could be delayed if not done).

       

            Assignee:
            Valentin Kavalenka
            Reporter:
            Tom Selander
            None
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: