ObjectDB ObjectDB

Issue #1483: NullPointer when accessing entity field

Type: Bug ReoprtVersion: 2.5.0Priority: NormalStatus: ActiveReplies: 3


following exception occurs when using objectdb:

at com.objectdb.o.TYW.<init>(TYW.java:103)
at com.objectdb.o.ENH.d(ENH.java:224)
at com.objectdb.o.ENT.Z(ENT.java:891)
at com.objectdb.o.LDR.K(LDR.java:836)
at com.objectdb.o.LDR.J(LDR.java:800)
at com.objectdb.o.LDR.UW(LDR.java:1023)
at com.objectdb.o.MST.aU(MST.java:508)
at com.objectdb.o.MST.aT(MST.java:434)
at com.objectdb.o.MST.U3(MST.java:407)
at com.objectdb.o.WRA.U3(WRA.java:251)
at com.objectdb.o.LDR.F(LDR.java:532)
at com.objectdb.o.LDR.E(LDR.java:466)
at com.objectdb.o.OBC.UJ(OBC.java:1073)
at com.objectdb.o.OBC.aK(OBC.java:763)
at com.objectdb.o.ENT.beforeAccess(ENT.java:1115)
at eu.ysoft.safeq.core.cache.entity.CacheableJobInfo.__odbGet_id(CacheableJobInfo.java:1)
at eu.ysoft.safeq.core.cache.entity.CacheableJobInfo.getPrimaryKey(CacheableJobInfo.java:828)
at eu.ysoft.cache.cluster.bucket.Bucket.add(Bucket.java:36)
at com.ysoft.cache.objectdb.cluster.bucket.ObjectCacheDBBucketManager$BucketSynchronizer.fillBucket(ObjectCacheDBBucketManager.java:154)
at com.ysoft.cache.objectdb.cluster.bucket.ObjectCacheDBBucketManager$BucketSynchronizer.run(ObjectCacheDBBucketManager.java:194)

It is very strange that the problem occurs when accessing field of enhanced class but not during reading/writing to objectdb. The issue occurs just once during our test, other instances of this enhanced class works without problems.

Objectdb logs does not contains any problem logs in this time.

Could you provide us some hint what is the cause of this problem?





The cause of this exception is unclear.

It happened during an access operation that required reloading of the object from the database.

The state of the object was unexpected and might have been changed during the operation. This could happen when an object is accessed in one thread while the EntityManager is manipulated concurrently in another thread (e.g. transaction is committed or the EntityManager is closed).

Is it possible that an EntityManager and/or its managed objects were accessed concurrently by more than one thread?

ObjectDB Support

We are using EntityManagers in following way:

for single read/write/update/delete:

- we create new EntityManager, do the operation in transaction and close the EntityManager

for batch operations we use ThreadLocal for storing EntityManagers:

 - we create EntityManager for this thread, store in ThreadLocal, (if not exists), begin transaction (if not exists), do the operations using EM in ThreadLocal, on batch end we commit transaction,delete from ThreadLocal and close EM


So I think there is now concurrent access on one EntityManager.

In single operations we just do the operation and close EM, so the objects are inmediatelly detatched...

Regarding the batch operations, where we usually do update on many objects and after that commit and close the EM. But I suppose that there is no problem if another EM is created in parallel, even if it access same object...or not?




> But I suppose that there is no problem if another EM is created in parallel, even if it access same object...or not?

It depends what is the "same object". Using multiple EntityManager instances concurrent threads may access the same database object, but each EntityManager has a separate memory representation of that object, and should not use memory objects that are managed by other EntityManager instances.

Apparently the stack trace shows that a managed object was accessed and during processing of that access (which required reloading its content from the database) the object became unmanaged with no reference to a valid EntityManager (this is the unexpected NullPointerException). If this is not caused by forbidden concurrent access then more information will be needed in order to understand the cause.

ObjectDB Support


To post on this website please sign in.