Helo Michael, I'm almost entirely sure that there is no sharing between threads. In our system the webservice handling method is created via ThreadLocal. There may be about 100 parallel handlers, each having its own thread for handling requests. When a handler starts, it obtains an EntityManager that is again created via ThreadLocal, thus there will be the same entity manager for the same thread. As much as I understand from openJPA, the entity manager handles the the entities and keeps track of them.
We never close the entity manager, but rather let it open for reuse, but as noted only in the same thread protected by ThreadLocal. No new threads are spawned or created while handling a single webservice request. No entities are being stored anywhere in the request handling code, neither statically or as instances. This is the dilemma here, I've really put efford in finding out if the entites have been shared, but I simply can't find any situation where this can be true. And just my two cents. Its fine that the state manager is nulled but in that case, this shall not lead to an NPE IMHO, don't you think? And even weirder is that in my error I do not even query a complex entity, like an embedded key or something. Its a simple Long-Value. That shall even WORK for detached objects, don't you think (again)? *smirk* Thanks for all your help in tracking this down. Best regards, Heiko [email protected] 29.07.2010 16:17 Bitte antworten an [email protected] An [email protected] Kopie Thema Re: NullPointerException in pcGet-Method Disclaimer: there's been a lot of discussion on OPENJPA-453 - I haven't digested all of it. The testcase for OPENJPA-453 has a single entity (not EntityManager) being accessed by two threads simultaneously. Heiko, are you sure the entity instances are not shared between threads? The StateManager may be nulled out when the entity is detached or evicted (based on OPENJPA-453). So the only way you _should_ be able to get into this case is if the entity is accessed on multiple threads - one thread detaches / evicts and the other uses it. Christiaan, I don't think the statemanager will be nulled on refresh() - if you've seen differently that's good data. -mike On Wed, Jul 28, 2010 at 6:09 AM, Christiaan <[email protected]>wrote: > > Hi Heiko, > your situation seems related to this one (also see related jira issue > http://issues.apache.org/jira/browse/OPENJPA-453): > > http://openjpa.208410.n2.nabble.com/NullPointerException-in-pcReplaceField-td2979657.html#a2979657 > > Although in this scenario the nullpointer relates to the statemanager of > the > embedded object. You do have an embedded primary key object, however the > nullpointer seems to happen in the owning object? I can imagine that > nullifying the statemanager happens with the refresh() call. My own > experience is that it happens with the evict() or commit() with > retainValues > set to false. > > Personally I think this really is a problem related to multithreading in > the > internal structures of OpenJPA, since the nullpointer happens in code > generated by OpenJPA. Accessing the statemanager and at the same time > nullifying it is something OpenJPA code is aware of, not the application > programmer. > > regards, > Christiaan > -- > View this message in context: > http://openjpa.208410.n2.nabble.com/NullPointerException-in-pcGet-Method-tp5337474p5345501.html > Sent from the OpenJPA Users mailing list archive at Nabble.com. > If you are not the intended addressee, please inform us immediately that you have received this e-mail in error, and delete it. We thank you for your cooperation.
