Skip to Main Content

Oracle Database Free

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to update JSON Relational Duality View by MLE SODA JavaScript API?

Yuji N.-OracleApr 12 2023

When calling SodaCollection.save() to update the document in SODA Collection backed by JSON Relational Duality View. It throws ORA-0001 unique constraint error because SQL insert is issued instead of SQL update.

ORA-04172: error in database callout from MLE at <dyn-src-js>:1:590
ORA-06512: at "APEX_220200.WWV_FLOW_CODE_EXEC_MLE", line 674
ORA-04173: ORA-42692: Cannot insert into JSON Relational Duality View 'EMP_DV': Error while inserting into table 'EMP'
ORA-04173: ORA-00001: unique constraint (APEXDEV.EMP_PK) violated
ORA-06512: at "SYS.DBMS_MLE", line 471
ORA-06512: at "APEX_220200.WWV_FLOW_CODE_EXEC_MLE", line 530
ORA-06512: at "APEX_220200.WWV_FLOW_CODE_EXEC_MLE", line 792
ORA-06512: at "APEX_220200.WWV_FLOW_CODE_EXEC", line 565

At first, create JSON Relational Duality View EMP_DV from standard EMP table.

create or replace json relational duality view emp_dv as
    emp @insert @update @delete
    {
        empno: empno
        ename: ename
        job: job
        mgr: mgr
        hiredate: hiredate
        sal: sal
        comm: comm
        deptno: deptno
    }
;

Then create SODA collection EMPCol.

declare
    l_col soda_collection_t;
begin
    l_col := dbms_soda.create_dualv_collection('EMPCol','EMP_DV');
end;

INSERT, UPDATE on JSON Relational Duality View using SQL are working. insertOne() and remove() on SODA Collection are also working. But save() is failed.

const connection = oracledb.defaultConnection();
const db = connection.getSodaDatabase();
const col = db.openCollection("EMPCol");
if ( col === null ) {
    throw `'EMPCol' does not exit`;
}
const emp = col.find().filter({"empno": 7839}).getOne();
const content = emp.getContent();
console.log(JSON.stringify(emp));
console.log(JSON.stringify(content));
const ukey = emp.key;
console.log(ukey);
content.sal = 5000;
content.comm = 200;
const updEmp = db.createDocument(
    content,
    {
        "key": ukey
    }
);
console.log(JSON.stringify(updEmp));
console.log(JSON.stringify(content));
col.save(updEmp);

I have checked the metadata of SODA Collection EMPCol, it is

{"schemaName":"APEXDEV","dualityViewName":"EMP_DV","keyColumn":{"name":"OBJECT_RESID","sqlType":"RAW","maxLength":4000,"assignmentMethod":"SERVER"},"contentColumn":{"name":"DATA","sqlType":"JSON"},"versionColumn":{"name":"OBJECT_ETAG","method":"NONE"},"readOnly":false}

It seems that name of keyColumn should be “EMPNO” and assignmentMethod should be “CLIENT” but these assignments can not be changed because they are required for SODA Collection created from JSON Relational Duality View.

How can I update JSON Relational Duality View by MLE SODA JavaScript API?

TIA

This post has been answered by MaxOrgiyan-Oracle on Apr 13 2023
Jump to Answer
Comments
Post Details
Added on Apr 12 2023
3 comments
797 views