Search code examples
database-connectionorientdb

ODatabaseException: Database instance is not set in current thread


I am new in OrientDB and use orientdb-community-1.7.4 version. I have two projects. Project A is used for manipulation with orientdb database (CRUD operation etc). Project B is a maven project (Liferay portlet) which includes Project A as a dependency.

In project B I create new Edge object, which is persisted in database. Then I want to get this object from database:

ApplicationContext appC = new ClassPathXmlApplicationContext("ApplicationContext.xml");
OrientDatabaseConnectionManager connMan = (OrientDatabaseConnectionManager) appC.getBean("orientConnectionManager");
OrientGraph graph = connMan.getGraph();
Edge edge = graph.getEdge("#37:20");

But I get this error. When I tried to get Edge object in Project A, I didn't get this error.

com.orientechnologies.orient.core.exception.ODatabaseException: Database instance is not set in current thread. Assure to set it with: ODatabaseRecordThreadLocal.INSTANCE.set(db);
    at com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal.get(ODatabaseRecordThreadLocal.java:31)
    at com.orientechnologies.orient.core.id.ORecordId.getRecord(ORecordId.java:293)
    at com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.getEdge(OrientBaseGraph.java:840)

OrientDatabaseConnectionManager.java (Project A)

package persistence.graphdb.graphDBConnectionInit;
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
import com.tinkerpop.blueprints.impls.orient.OrientGraphFactory;

    /**
     * Class manages connection to the graph database. 
     * See http://www.orientechnologies.com/docs/1.7.8/orientdb.wiki/Java-Tutorial:-Introduction.html
     * for the graph database instantiation
     */

    public class OrientDatabaseConnectionManager {
        private OrientGraphFactory factory;

        public OrientDatabaseConnectionManager(String path, String name, String pass) {
            factory = new OrientGraphFactory(path, name, pass).setupPool(1,10);
        }

        /**
         * Method returns graph instance from the factory's pool.
         * @return 
         */

        public OrientGraph getGraph(){
            return factory.getTx();
        } 

    }

ApplicationContext.xml (Project A)

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/util  http://www.springframework.org/schema/util/spring-util-3.1.xsd">


    <context:property-placeholder properties-ref="graphDbProperties"/>


    <util:properties id="graphDbProperties">
        <prop key="orientEmbeddedDbPath">plocal:/Users/and/orientdb-community-1.7.4/databases/graphDb</prop>
        <prop key="orientName">admin</prop>
        <prop key="orientPass">admin</prop>
    </util:properties>

    <!-- ORIENT DB config -->
    <bean id="orientConnectionManager" class="persistence.graphdb.graphDBConnectionInit.OrientDatabaseConnectionManager">
        <constructor-arg index="0" value="${orientEmbeddedDbPath}"/>
        <constructor-arg index="1" value="${orientName}"/>
        <constructor-arg index="2" value="${orientPass}"/>
    </bean>

</beans>

Solution

  • I think this is a bug in orientdb, because when I tried it on 32-bit Windows 7, it works, but on OS X I get this error.

    This solution works also on OSX.