【问题标题】:OrientDB - database object not syncronized with current threadOrientDB - 数据库对象未与当前线程同步
【发布时间】:2016-04-12 21:01:28
【问题描述】:

我对 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();
}

【问题讨论】:

  • 你能发布更多关于连接到 templateDb 的代码吗?
  • @AlessandroRota:我已经用连接方法更新了我的问题
  • 您使用的是哪个版本的 OrientDb?
  • 版本为:东方2.1.4
  • 您可以在此链接查看文档orientdb.com/docs/2.1/Java-Multi-Threading.html

标签: java orientdb orientdb-2.1


【解决方案1】:

在 orientDB 版本 2.1 中,您必须明确与您的 DB 对象相关的 activateOnCurrentThread。尝试如下:

templateDb.activateOnCurrentThread();

【讨论】:

  • 是的,我采用了这个解决方案。您已将评论转换为答案,我接受。谢谢
猜你喜欢
  • 2014-06-17
  • 2016-06-25
  • 2013-04-02
  • 1970-01-01
  • 2012-02-07
  • 2017-01-06
  • 2015-01-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多