2 Replies Latest reply on Sep 15, 2020 8:17 AM by MaxOrgiyan-Oracle

    Duplicate records getting inserted from Java code in SODA colletion Oracle 19C

    4313552

      Hi All,

       

      I am new to Oracle SODA. I am working on migartion from old Oracle to New Oracle 19C JSON document.

      I am working on CRUD operation through Java. While working on Insert a new document I am facing difficulty of duplicate record. I am able to insert the records but when I insert the same record it goes as duplicate and Oracle 19C is allowing. I may have missed something while creating the Collection. The docId and Vesrion are all generated. I can see from database that when I insert the same data as input, the generated version column becomes the same. The docId is different always. How to fix this duplicate issue ?

      Please help me.

       

      Below is the SODA table and you can see vesrion column is duplicate for duplicate input request.

       

       

       

       

       

      Below is the piece of Java code I am using for create new document(insert) :

       

      public String createDocument(DataSourceConfig dsConfig, String collectionName, String key, String documentString)

      throws PectabException {

      Connection conn = null;

      OracleDocument insertedDoc = null;

      String insertResult = "";

      try {

      // Get an OracleRDBMSClient - starting point of SODA for Java application

      OracleRDBMSClient oraClient = new OracleRDBMSClient();

      conn = dsConfig.getConnection();

      // Get a database.

      OracleDatabase db = null;

      db = oraClient.getDatabase(conn);

      OracleCollection col = db.openCollection(collectionName);

      OracleDocument document = db.createDocumentFromString(documentString);

      // Insert document in SODA Collection

      insertedDoc = col.insertAndGet(document);

      if (null != insertedDoc.getKey()) {// Get the generated document key

      insertResult = insertedDoc.getKey();

      }

      } catch (OracleException e) {

      LOG.error("OracleException or IOException in creating Pectab document in SODA database. {}", e);

      throw new PectabException(ErrorCodes.ERROR_CODE.DOCUMENT_FETCH_EXCEPTION, e);

      } catch (Exception e) {

      LOG.error("createDocument :: {} {}", ERROR_MSG_DOC_FETCH, e);

      throw new PectabException(ErrorCodes.ERROR_CODE.DOCUMENT_FETCH_EXCEPTION, e);

      } finally {

      try {

      if (null != conn) {

      conn.close();

      }

      } catch (SQLException e) {

      LOG.error("Error in inserting Pectab soda document in database. {}", e);

      }

      }

      return insertResult;

      }

        • 1. Re: Duplicate records getting inserted from Java code in SODA colletion Oracle 19C
          4313552

          can anybody please reply on this as I am till stuck on this Admin Panel

          • 2. Re: Duplicate records getting inserted from Java code in SODA colletion Oracle 19C
            MaxOrgiyan-Oracle

            Our sincere apologies, somehow we (SODA team) missed this question. Sorry for the late response!

             

            Not sure I understand the issue though... are you saying the version has the same value for different inserted documents? If those documents have exactly the same content, then this is expected, assuming you're using SHA256 versioning method (which is the default). For this default versioning method, the version is simply a SHA256 hash of the content. So, if you have two or more documents with the same content, their versions will be the same. Versions are only there to indicate that a document content has changed: any time the document gets updated, assuming it has a different content, the SHA256 version will be different. This is useful for things like optimistic locking or for generating eTags in REST type apps. Versions are not used to compare different documents (i.e. documents with different keys).

             

            Does this answer your question? If not, please let us know.