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>(); ...