Database instance is not set in current thread

248 views
Skip to first unread message

Nolan Darilek

unread,
Apr 27, 2012, 9:16:05 AM4/27/12
to orient-...@googlegroups.com
Thanks for the tip about marking a class persistent. That seems to have
worked. Now I'm encountering an exception when trying to save records,
namely that the database instance is not set in the current thread.

The exception helpfully tells me to call
ODatabaseRecordThreadLocal.INSTANCE.set(db) which I do, but this seems
to want an ODatabaseRecord rather than an an ODatabaseObjectTx.

What am I missing? I've glanced at the multi-threading wiki page, but it
seems like I'm trying to follow the instructions in the exception. I'm
creating my database like so, in case it helps:

lazy val db = new ODatabaseObjectTx(Props.get("database",
"memory:stackman"))

def init() {
if(db.exists) db.open("admin", "admin") else db.create()
db.getMetadata().getSchema().createClass("Stacktrace")
db.registerHook(this)
}

with init() called when my app starts.

Thanks.

mproch

unread,
Apr 27, 2012, 10:03:46 AM4/27/12
to orient-...@googlegroups.com
can you post the code that throws exception?

Nolan Darilek

unread,
Apr 27, 2012, 10:08:49 AM4/27/12
to orient-...@googlegroups.com
On 04/27/2012 09:03 AM, mproch wrote:
> can you post the code that throws exception?
>
It'd be fairly difficult, because it is written in Scala and part of a
larger project.

I think that my issue is less about threading, and more about how do I
go from the ObjectDatabaseTx to an ODocument. Are databases instances of
ODocument? It seems like if I'm setting a database, then I should be
able to pass the database instance I've created.

Thanks.

Luca Molino

unread,
Apr 27, 2012, 12:27:47 PM4/27/12
to orient-...@googlegroups.com
With the ObjectDatabaseTx you can get the ODatabaseRecord by calling db.underlying() (and cast it to ODatabaseRecord)

2012/4/27 Nolan Darilek <no...@thewordnerd.info>

luukes

unread,
May 2, 2012, 4:29:49 AM5/2/12
to orient-...@googlegroups.com
Hi Luca,

since I'm having the same problem I change over from the issue (778) to this thread because it belongs here:

I have a webapp-filter which looks like this - the exception is thrown in aquire()

OObjectDatabaseTx database
try {
  database = OObjectDatabasePool.global().acquire( getUrl(), getUser(), getPwd() );
  return handler.service( request, response );
} finally {
  database.close();
}
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:28)
   	at com.orientechnologies.orient.object.enhancement.OObjectEntitySerializer.registerClass(OObjectEntitySerializer.java:155)
   	at com.orientechnologies.orient.object.entity.OObjectEntityClassHandler.registerEntityClass(OObjectEntityClassHandler.java:39)
   	at com.orientechnologies.orient.object.entity.OObjectEntityClassHandler.registerEntityClass(OObjectEntityClassHandler.java:33)
   	at com.orientechnologies.orient.core.entity.OEntityManager.setClassHandler(OEntityManager.java:134)
   	at com.orientechnologies.orient.object.db.OObjectDatabaseTx.init(OObjectDatabaseTx.java:561)
   	at com.orientechnologies.orient.object.db.OObjectDatabaseTxPooled.reuse(OObjectDatabaseTxPooled.java:48)
   	at com.orientechnologies.orient.core.db.ODatabasePoolBase$1.reuseResource(ODatabasePoolBase.java:58)
   	at com.orientechnologies.orient.core.db.ODatabasePoolBase$1.reuseResource(ODatabasePoolBase.java:42)
   	at com.orientechnologies.common.concur.resource.OResourcePool.getResource(OResourcePool.java:56)
   	at com.orientechnologies.orient.core.db.ODatabasePoolAbstract.acquire(ODatabasePoolAbstract.java:70)
   	at com.orientechnologies.orient.core.db.ODatabasePoolAbstract.acquire(ODatabasePoolAbstract.java:52)
   	at com.orientechnologies.orient.core.db.ODatabasePoolBase.acquire(ODatabasePoolBase.java:88)

luukes

unread,
May 2, 2012, 7:46:24 AM5/2/12
to orient-...@googlegroups.com
For the records - fixed in revision 5457
 
Reply all
Reply to author
Forward
0 new messages