Home » Support » Forum » spuriously objectdb objects have null references

spuriously objectdb objects have null references

#1

from time to time we have in a multi threaded environment objects where all the references are null (i.e. references actions, childNodes), even after a subsequent refresh.

we are using a separate entityManager per thread and have a central point where we encapsulated all the needed entitymanager methods and protected them with synchronized like:

 

...

private static Object lockBegin = new Object();

public static void begin(EntityManager threadEntityManager){
  synchronized(lockBegin){
   try {
    threadEntityManager.getTransaction().begin();
   } catch (Exception e){
   }
  }
}

...

 

the reference definitions are (for the null references above):

...

@OneToMany(fetch=FetchType.LAZY)
@Index
public List<Action> actions = new ArrayList<Action>();

...

@OneToMany(fetch=FetchType.LAZY)
@Index
public List<ObjectNode> childNodes = new ArrayList<ObjectNode>();

...

 

 

 

#2

When an entity object is detached (e.g. when the EntityManager is closed), ObjectDB replaces lazy loaded collections that have not been loaded with null values. Detached objects cannot be refreshed.

Does it happen only for lazy collection fields?

Could you please check the status of the entity objects and these collection fields when this happens using isLoaded method in PersistenceUtiljavax.persistence.PersistenceUtilJPA interfaceUtility interface between the application and the persistence provider(s).See JavaDoc Reference Page...?

 

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
#3

we checked it and in the case when we have the null collections it is not loaded.

but why can we have such a behaviour ? It is only happening under heavy multithread load 

#4

> but why can we have such a behaviour ?

The main goal is to make sure that unloaded fields are known as unloaded after detachment. This way you can easily tell the difference (after detachment) between a collection that is really empty and a collection that was just not loaded.

You may avoid this by using the no-detach setting:

System.setProperty("objectdb.temp.no-detach", "true");

before first access of ObjectDB or as a -D command line JVM argument.

If you just prefer an empty collection instead of null it wouldn't be difficult to enable such an option.

But of course, this is based on the assumption that these fields are null because of detachment.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
#5

we implemented now a combination of

- System.setProperty("objectdb.temp.no-detach", "true");

- doing a entityManager.find in case the object is not loaded

what seems to cover our problem, thanks for the support


Post Reply

To post a reply and/or subscribe to update notifications - please login