Search code examples
orientdb

Issue with embeddedmap insert with jdbc


When i tried to insert an embeddedmap using jdbc the following exception pop up

com.orientechnologies.orient.core.exception.OValidationException: impossible to convert value of field "permission"

at com.orientechnologies.orient.core.record.impl.ODocument.autoConvertValues(ODocument.java:2270)
at com.orientechnologies.orient.core.record.impl.ODocument.validate(ODocument.java:1991)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.save(ODatabaseDocumentTx.java:2519)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.save(ODatabaseDocumentTx.java:121)
at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:1768)
at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:1759)
at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:81)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLInsert.saveRecord(OCommandExecutorSQLInsert.java:323)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLInsert.execute(OCommandExecutorSQLInsert.java:224)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.execute(OCommandExecutorSQLDelegate.java:90)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.executeCommand(OAbstractPaginatedStorage.java:1522)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.command(OAbstractPaginatedStorage.java:1503)
at com.orientechnologies.orient.core.command.OCommandRequestTextAbstract.execute(OCommandRequestTextAbstract.java:67)
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.command(ONetworkProtocolBinary.java:1323)
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.executeRequest(ONetworkProtocolBinary.java:400)
at com.orientechnologies.orient.server.network.protocol.binary.OBinaryNetworkProtocolAbstract.execute(OBinaryNetworkProtocolAbstract.java:223)
at com.orientechnologies.common.thread.OSoftThread.run(OSoftThread.java:77)

Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map at com.orientechnologies.orient.core.record.impl.ODocument.autoConvertValues(ODocument.java:2256) ... 16 more

what is the issue here


UPDATE CODE:

Map<String,Object> permission = new HashMap<>();
permission.put("user_permission",Byte.valueOf("15"));
new JdbcTemplate(datasource).update("Insert into Role SET name = ?, permission = ?","Role1",permission);

Note: I am using spring jdbc


Solution

  • I have tried with the following code

    Properties info = new Properties();
    info.put("user", "root");
    info.put("password", "root");
    
    Connection conn = (OrientJdbcConnection) DriverManager.getConnection("jdbc:orient:remote:localhost/test", info);
    
    Statement statement = conn.createStatement();
    
    Map<String,Object> permission = new HashMap<String,Object>();
    permission.put("user_permission",Byte.valueOf("15"));
    
    Gson gson = new Gson();
    String myString = gson.toJson(permission);
    
    String query= "Insert into ORole SET name = 'Role1' , permission = " + myString;
    
    statement.execute(query);
    

    enter image description here

    enter image description here

    Hope it helps.