Jean-Baptiste BRIAUD -- Novlog wrote:
>
> Did you compared using == what you think is different instance of
> EntityManager ?
> Reading your message tend to prove that EntityManager is shared and
> when you think you got a new one it is not a new one.
>
Why I have to check an instance returned by a threadlocal variable ??
I use the following Th ThreadLocal<EntityManager>:
private static class ThreadLocalEntityManager extends
ThreadLocal<EntityManager> {
/* (non-Javadoc)
* @see java.lang.ThreadLocal#get()
*/
@Override
public EntityManager get() {
/* Get the current entity manager */
EntityManager em = super.get();
/* The entity manager was closed */
if (!em.isOpen()) {
/* Create a new entity manager */
em = factory.createEntityManager();
/* Update the entity manager */
set(em);
}
return em;
}
/* (non-Javadoc)
* @see java.lang.ThreadLocal#initialValue()
*/
@Override
protected EntityManager initialValue() {
return factory.createEntityManager();
}
}
Where factory is a static EntityManagerFactory.
What is going wrong ??
-----
Not everything that can be counted counts, and not everything that counts can
be counted - Albert Einstein
--
View this message in context:
http://n2.nabble.com/Persist-issue-in-multithreaded-environment-tp3377510p3377741.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.