Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] EntityManager life-cycle..

Hi,

It seems that the recommended pattern is to have a relatively shortly lived EntityManager and use it with the following sort of code

        try {
            em = getEntityManager();
            em.getTransaction().begin();
            //.... do something....
            em.getTransaction().commit();
        } finally {
            if (em != null) {
                em.close();
            }
        }

where the getEntityManager() call uses a long lived EntityManagerFactory to get new EntityManager. I am having a problem with this pattern in a multi-threaded J2SE environment (specifically Netbeans RCP), where I am getting all sorts of strange exceptions - often  the following

Caused by: java.lang.NullPointerException
        at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:340)
        ... 17 more

caused by the class field "processor" being null when two statements earlier it was obviously not null (if in the same thread)

This would tend to suggest that there are threading issues with the EntityManagerFactory/EntityManager that I am not aware of - does anyone have experience of any special tricks necessary to make Eclipselink work properly in Netbeans RCP? I am using Eclipselink 2.2.0 and Netbeans RCP 6.9.1.


Paul.

Back to the top