Skip to main content

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

Hi Tom


The EntityManagerFactory is created as a static field of BaseJPAController which is the base class of all the *JPAController classes - there is a extra complexity in the Rack Entity class in that it has a static initializer that looks like

    static {
        
        try {
            RackJpaController instance = new RackJpaController();
            if((stationRack = instance.findRack(Integer.valueOf(255))) == null){
                stationRack = new Rack(Integer.valueOf(255));
                stationRack.setName("Station");
                instance.create(stationRack);
            }
            if((baselineRack = instance.findRack(Integer.valueOf(101))) == null){
                baselineRack = new Rack(Integer.valueOf(101));
                baselineRack.setName("Baseline");
                instance.create(baselineRack);
            }
        } catch (PreexistingEntityException e) {
            throw new RuntimeException("A Rack has already been created", e);
        } catch (Exception e) {
            throw new RuntimeException("Error creating rack", e);
        }
        
    }

as Racks are the basic containers for all other objects and there need to be two pre-existing for the application to be able to function - stationRack and baselineRack are static members of Rack. The code that does the equivalent of what causes the error below runs fine in a unit test - so it seems that it is running within Netbeans RCP that the problem occurs - perhaps it is to do with an interaction between the classloading requirements of Eclipselink and Netbeans RCP....

Paul.

On 2011-03 -28, at 21:17, Tom Ware wrote:

> Hi Paul,
> 
>  Does the EntityManagerFactory exist prior to the call to getEntityManager()?  If not, what happens if you ensure it is created prior to any getEntityManager() calls?
> 
> -Tom
> 
> 
> Paul Harrison wrote:
>> The rest of the stack trace is below - I think that I have at least 2 or 3 queries happening "simultaneously" during the startup, and from what I can tell running in the debugger the error seems to happen after one of  the queries has called the em.close(), so it seems that somehow there is some shared state between EntityManager instances that is being cleared by the close()... but it is a little tricky to see exactly what is going on as I am new to netbeans RCP....
>> [EL Finer]: 2011-03-28 20:45:34.424--Thread(Thread[main,5,IDE Main])--JavaSECMPInitializer - transformer is null.
>> SEVERE [org.netbeans.core.modules]
>> Local Exception Stack: Exception [EclipseLink-28019] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.EntityManagerSetupException
>> Exception Description: Deployment of PersistenceUnit [uk.ac.man.jb.emerlin_dbaccess_nbm_1.0-SNAPSHOTPU] failed.
>> Internal Exception: java.lang.NullPointerException
>>        at org.eclipse.persistence.exceptions.EntityManagerSetupException.deployFailed(EntityManagerSetupException.java:218)
>>        at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:367)
>>        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:185)
>>        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:242)
>>        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:230)
>>        at uk.ac.man.jb.emerlin.dbaccess.BaseJPAController.getEntityManager(BaseJPAController.java:28)
>>        at uk.ac.man.jb.emerlin.dbaccess.RackJpaController.findRackEntities(RackJpaController.java:107)
>>        at uk.ac.man.jb.emerlin.dbaccess.RackJpaController.findRackEntities(RackJpaController.java:99)
>>        at uk.ac.man.jb.emerlin.emcbegui.Installer.restored(Installer.java:32)
>>        at org.netbeans.core.startup.NbInstaller.loadCode(NbInstaller.java:426)
>>        at org.netbeans.core.startup.NbInstaller.load(NbInstaller.java:366)
>>        at org.netbeans.ModuleManager.enable(ModuleManager.java:944)
>>        at org.netbeans.core.startup.ModuleList.installNew(ModuleList.java:318)
>>        at org.netbeans.core.startup.ModuleList.trigger(ModuleList.java:254)
>>        at org.netbeans.core.startup.ModuleSystem.restore(ModuleSystem.java:286)
>>        at org.netbeans.core.startup.Main.getModuleSystem(Main.java:172)
>>        at org.netbeans.core.startup.Main.start(Main.java:302)
>>        at org.netbeans.core.startup.TopThreadGroup.run(TopThreadGroup.java:114)
>>        at java.lang.Thread.run(Thread.java:680)
>> Caused by: java.lang.NullPointerException
>>        at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:340)
>>         ... 17 more
>> Caused: javax.persistence.PersistenceException
>>        at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:367)
>>        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:185)
>>        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:242)
>>        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:230)
>>        at uk.ac.man.jb.emerlin.dbaccess.BaseJPAController.getEntityManager(BaseJPAController.java:28)
>>        at uk.ac.man.jb.emerlin.dbaccess.RackJpaController.findRackEntities(RackJpaController.java:107)
>>        at uk.ac.man.jb.emerlin.dbaccess.RackJpaController.findRackEntities(RackJpaController.java:99)
>>        at uk.ac.man.jb.emerlin.emcbegui.Installer.restored(Installer.java:32)
>>        at org.netbeans.core.startup.NbInstaller.loadCode(NbInstaller.java:426)
>>        at org.netbeans.core.startup.NbInstaller.load(NbInstaller.java:366)
>>        at org.netbeans.ModuleManager.enable(ModuleManager.java:944)
>>        at org.netbeans.core.startup.ModuleList.installNew(ModuleList.java:318)
>>        at org.netbeans.core.startup.ModuleList.trigger(ModuleList.java:254)
>>        at org.netbeans.core.startup.ModuleSystem.restore(ModuleSystem.java:286)
>>        at org.netbeans.core.startup.Main.getModuleSystem(Main.java:172)
>>        at org.netbeans.core.startup.Main.start(Main.java:302)
>>        at org.netbeans.core.startup.TopThreadGroup.run(TopThreadGroup.java:114)
>> [catch] at java.lang.Thread.run(Thread.java:680)
>> On 2011-03 -28, at 18:15, Tom Ware wrote:
>>> Hi Paul,
>>> 
>>> Can you please provide the rest of the stack trace?  (At least including the first line of code that does not belong to EclipseLink)
>>> 
>>> -Tom
>>> 
>>> Paul Harrison wrote:
>>>> 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.
>>>> _______________________________________________
>>>> eclipselink-users mailing list
>>>> eclipselink-users@xxxxxxxxxxx
>>>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>>> _______________________________________________
>>> eclipselink-users mailing list
>>> eclipselink-users@xxxxxxxxxxx
>>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>> Dr. Paul Harrison
>> JBCA, Manchester University
>> http://www.manchester.ac.uk/jodrellbank
>> _______________________________________________
>> eclipselink-users mailing list
>> eclipselink-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Dr. Paul Harrison
JBCA, Manchester University
http://www.manchester.ac.uk/jodrellbank





Back to the top