使用jdbc插入嵌入式映射的问题

时间:2016-03-24 10:38:16

标签: orientdb

当我尝试使用jdbc插入嵌入式地图时会弹出以下异常

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)

引起:java.lang.ClassCastException:java.lang.String无法强制转换为java.util.Map     在com.orientechnologies.orient.core.record.impl.ODocument.autoConvertValues(ODocument.java:2256)     ......还有16个

这里有什么问题

更新 代码:

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);

注意: 我正在使用spring jdbc

1 个答案:

答案 0 :(得分:0)

我尝试使用以下代码

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

希望它有所帮助。