我在Java中使用OrientDB ODatabaseDocument对象存在严重问题。
为了防止ODatabaseDocument对象(templateDb)和当前线程之间的去同步化,在关闭连接之前,我强制使用activateOnCurrentThread同步,但是当我关闭连接时,我总是得到以下错误:
java.lang.IllegalStateException: Current database instance (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx@302a2a53) is not active on current thread (Thread[btpool0-3,5,main]). Current active database is: com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx@2040c7d9
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.checkIfActive(ODatabaseDocumentTx.java:3138)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.command(ODatabaseDocumentTx.java:667)
我的代码:
finally {
if (!templateDb.isActiveOnCurrentThread()) {
templateDb.activateOnCurrentThread();
}
templateDb.close();
}
修改
String connectionUrl = customer.getDbName();
if (!connectionUrl.startsWith("remote:")) {
connectionUrl = storageConnectionPrefix + connectionUrl;
}
try {
ODatabaseDocumentTx g = new ODatabaseDocumentTx(connectionUrl);
g.activateOnCurrentThread();
g.open(username, password);
g.begin();
return g;
} catch (Exception e) {
e.printStackTrace();
}
答案 0 :(得分:2)
在orientDB版本2.1中,您必须显示与您的数据库对象相关的activateOnCurrentThread
。请尝试如下:
templateDb.activateOnCurrentThread();