orientechnologies / orientjs

The official fast, lightweight node.js client for OrientDB
http://orientdb.com
Other
326 stars 68 forks source link

java.lang.ClassCastException Query Builder Error (v3.X.X) #377

Closed creisle closed 5 years ago

creisle commented 5 years ago

System information

Orientjs version: 3.0.5 orientdb version: 3.0.20 node version: v10.13.0

Expected Behaviour

The insert operation to suceed

Actual Behaviour

Throws this error

{ OrientDB.RequestError: null
    at child.Operation.parseError (/home/node_modules/orientjs/lib/client/network/protocol37/operation.js:1224:13)
    at child.Operation.consume (/home/node_modules/orientjs/lib/client/network/protocol37/operation.js:566:35)
    at ONetworkConnection.Connection.process (/home/node_modules/orientjs/lib/client/network/conn.js:462:17)
    at ONetworkConnection.Connection.handleSocketData (/home/node_modules/orientjs/lib/client/network/conn.js:344:20)
    at Socket.emit (events.js:182:13)
    at addChunk (_stream_readable.js:283:12)
    at readableAddChunk (_stream_readable.js:264:11)
    at Socket.Readable.push (_stream_readable.js:219:10)
    at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
  name: 'OrientDB.RequestError',
  message: null,
  data: {},
  isMVCC: [Function],
  isTokenException: [Function],
  previous: [],
  code: 5,
  identifier: 0,
  id: 1,
  type: 'java.lang.ClassCastException',
  hasMore: 0 }

Minimum Reproducible Example

const {OrientDBClient} = require('orientjs');

const test = async (conf) => {
    const server = await OrientDBClient.connect({
        host: conf.DB_HOST,
        port: conf.DB_PORT
    });
    await server.createDatabase({
        name: DB_NAME,
        username: conf.DBS_USER,
        password: conf.DBS_PASS
    });
    const db = await server.session({
        name: DB_NAME,
        username: conf.DBS_USER,
        password: conf.DBS_PASS
    });
    // set up the schema
    await db.command('create class Parent extends V').all();
    await db.command('create class Position').all();
    await db.command('create property Parent.position Embedded Position');
    await db.command('create property Position.pos INTEGER (mandatory TRUE, MIN 1)').all();

    // now create the record using the query builder
    let record;
    try {
        record = await db.insert().into('Parent').set({
            position: {'@class': 'Position', pos: 1}
        }).one();
    } catch (err) {
        await cleanup(server, conf);
        throw err;
    }
    await cleanup(server, conf);
    return record;
};

I think this has something to do with the "MIN" constraint

creisle commented 5 years ago

It also worth nothing that I can create this record using the same class schema successfully when done though the db console bypassing orientjs

wolf4ood commented 5 years ago

Hi @creisle

the main problem is on the wired protocol. OrientJS when serializing number uses Long java type, but in this case the property is integer. And that explains the class cast exception. OrientDB should automatically convert to the declared type on the schema. I've provided a fix. It is on testing now. If the tests passes it will be available in the next release

Thanks

Enrico

wolf4ood commented 5 years ago

Hi @creisle

the fix has been merged. It will be available in the next OrientDB 3.0.22 release

Thanks

creisle commented 5 years ago

Great! Thank you :)

creisle commented 5 years ago

Hi @wolf4ood,

I just tried this is orientdb 3.0.22 and the error is still there