I have a serious problem with OrientDB ODatabaseDocument object in Java.
To prevent the desyncronization between ODatabaseDocument object (templateDb) and current thread, before close the connection, I force with activateOnCurrentThread the syncronization, but when I close the connection, I always get the following error:
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)
My code:
finally {
if (!templateDb.isActiveOnCurrentThread()) {
templateDb.activateOnCurrentThread();
}
templateDb.close();
}
EDIT
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();
}
In orientDB version 2.1 you must explicit the
activateOnCurrentThread
related to your DB object. Try as follow: