Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Eclipse RCP - EntityManagerFactory == null

Hi Christian,

I apologize if I have missed this earlier in the thread, but the most common reason the persistence unit cannot be found is that the correct classloader has not been provided at EntityManagerFactory creation time. We need access to a classloader that can load META-INF/persistence.xml as a resource.

  Here's what we do in the example:

    private EntityManagerFactory getEntityManagerFactory() {
        if (emf == null) {
            HashMap properties = new HashMap();
properties.put(PersistenceUnitProperties.CLASSLOADER, this.getClass().getClassLoader());
            emf = new PersistenceProvider().createEntityManagerFactory(
                    PU_NAME,
                    properties);
        }
        return emf;
    }

-Tom

Christian August Michelsen wrote:
Tim Hollosy skrev:
What's the console output/logging output before the NPE? Set your
logging level to Finest and post it, that would help.

Well after some serious head-against-hard-surface getting the logging going I suddenly started getting a helpfull little piece of info.

18:16:05 ERROR (Log4JLogListener.java:67) - Log4JLogListener.logging(...): Unable to create view ID jpaprototypepluginview.View2: Exception Description: An attempt has been made to use PersistenceUnit [yazcatprototype], but no bundle is available that defines that persistence unit. (code 0)
Local Exception Stack:
Exception [EclipseLink-28027] (Eclipse Persistence Services - 1.0.2 (Build 20081024)): org.eclipse.persistence.exceptions.EntityManagerSetupException Exception Description: An attempt has been made to use PersistenceUnit [yazcatprototype], but no bundle is available that defines that persistence unit.

So basicly it can't find the persistence.xml, which sorta was on my list of possible reasons. The persistence.xml is in a bundle with my annotated classes. Oddly enough I have no problem importing those classes into the bundle that actually tries to start the EntityManagerFactory, but I guess there is some huge barn door I'm overlooking.

Any suggestions what I should do?



Back to the top