Home » Eclipse Projects » EclipseLink » createEntityManagerFactory() returns null in RichClient application(createEntityManagerFactory() works fine in JUnit, but not in RichClient application.)
createEntityManagerFactory() returns null in RichClient application [message #487011] |
Mon, 21 September 2009 13:19 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Matthew Fitzgerald![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=kingofnobid%40gmail.com) Messages: 13 Registered: July 2009 |
Junior Member |
|
|
I am creating a RichClient application with Persistence, but createEntityManagerFactory() returns null. I have been searching, but can not find any info on the web. Hoping someone can point me in the right direction.
Background:
I am using Galileo / EMF / Teneo / EclipeLink / Derby and all are the latest releases. I have a successfully created a EntityManagerFactory and persisted my EMF model when doing my backend development running under JUnit. Now I am working on the frontend and createEntityManagerFactory() returns null. My code is as follows and it is the same in my RC app and in JUnit:
HashMap<String, Object> properties = new HashMap<String, Object>();
properties.put(PersistenceUnitProperties.CLASSLOADER, this.getClass().getClassLoader());
PersistenceProvider pp = new PersistenceProvider();
emf = pp.createEntityManagerFactory(getPersistenceUnitName(), properties);
em = emf.createEntityManager();
Debugging the problem I see that the classLoader returned by this.getClass().getClassLoader() is different between my RC app and JUnit:
my RC app: org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader@1530551
JUnit: sun.misc.Launcher$AppClassLoader@fabe9
Should I be using the createEntityManagerFactory(emName, properties, classLoader) version of createEntityManagerFactory with a different classLoader? If not, then tracing thru the createEntityManagerFactory() call in org.eclipse.persistence.jpa.PersistenceProvider.class I see that problem appears to be when I get to Enumeration<URL> resources = classLoader.getResources("META-INF/persistence.xml"); which does not return with my persistence.xml when running my RC app, but is fine with JUnit. I have included the path to META-INF/persistence.xml (which is in the model) and have even copied it to my RC app's src folder, but no joy.
Any thoughts would be appreciated.
|
|
|
Re: createEntityManagerFactory() returns null in RichClient application [message #487466 is a reply to message #487011] |
Wed, 23 September 2009 11:13 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Thomas Haskes![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=t.haskes%40t-p.com) Messages: 147 Registered: July 2009 |
Senior Member |
|
|
Hi Matthew,
first thing taht popped into my head was that you need to put the entry
JPA-PersistenceUnits: your_pu
into the manifest.mf of the plugin that holds the persistence.xml.
Second thing is that I created my EMF differently, like this
HashMap<String, Object> properties = new HashMap<String, Object>();
properties.put(PersistenceUnitProperties.CLASSLOADER,
this.getClass().getClassLoader());
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("mypu", properties);
Note that the classloader that you provide the emf with must be able to
see your persistence.xml.
HTH,
Tom
Matthew Fitzgerald schrieb:
> I am creating a RichClient application with Persistence, but
> createEntityManagerFactory() returns null. I have been searching, but
> can not find any info on the web. Hoping someone can point me in the
> right direction.
>
> Background:
> I am using Galileo / EMF / Teneo / EclipeLink / Derby and all are the
> latest releases. I have a successfully created a EntityManagerFactory
> and persisted my EMF model when doing my backend development running
> under JUnit. Now I am working on the frontend and
> createEntityManagerFactory() returns null. My code is as follows and it
> is the same in my RC app and in JUnit:
>
> HashMap<String, Object> properties = new HashMap<String,
> Object>();
> properties.put(PersistenceUnitProperties.CLASSLOADER,
> this.getClass().getClassLoader());
> PersistenceProvider pp = new PersistenceProvider();
> emf =
> pp.createEntityManagerFactory(getPersistenceUnitName(), properties);
> em = emf.createEntityManager();
>
> Debugging the problem I see that the classLoader returned by
> this.getClass().getClassLoader() is different between my RC app and JUnit:
> my RC app:
> mailto:org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader@1530551
> JUnit:
> sun.misc.Launcher$mailto:AppClassLoader@fabe9
>
> Should I be using the createEntityManagerFactory(emName, properties,
> classLoader) version of createEntityManagerFactory with a different
> classLoader? If not, then tracing thru the createEntityManagerFactory()
> call in org.eclipse.persistence.jpa.PersistenceProvider.class I see that
> problem appears to be when I get to Enumeration<URL> resources =
> classLoader.getResources("META-INF/persistence.xml"); which does not
> return with my persistence.xml when running my RC app, but is fine with
> JUnit. I have included the path to META-INF/persistence.xml (which is
> in the model) and have even copied it to my RC app's src folder, but no
> joy.
>
> Any thoughts would be appreciated.
|
|
|
Re: createEntityManagerFactory() returns null in RichClient application [message #488236 is a reply to message #487466] |
Sat, 26 September 2009 14:19 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Matthew Fitzgerald![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=kingofnobid%40gmail.com) Messages: 13 Registered: July 2009 |
Junior Member |
|
|
Tom:
Thanks for your help. It is very much appreciated! I was able to get everything working thanks to your ideas. Some comments on what I found:
Thomas Haskes wrote on Wed, 23 September 2009 07:13 | Second thing is that I created my EMF differently, like this
HashMap<String, Object> properties = new HashMap<String, Object>();
properties.put(PersistenceUnitProperties.CLASSLOADER,
this.getClass().getClassLoader());
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("mypu", properties);
|
I have based my code on the org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests example. So, I actually use the EclipseLink persistence version: org.eclipse.persistence.jpa.osgi.PersistenceProvider instead of javax.persistence.Persistence which I am guessing you are using. I am expecting that both are correct for our particular applications.
Thomas Haskes wrote on Wed, 23 September 2009 07:13 | first thing taht popped into my head was that you need to put the entry
JPA-PersistenceUnits: your_pu
into the manifest.mf of the plugin that holds the persistence.xml.
|
I am not finding much documentation on this and the EclipseLink examples do not seem to use the declaration. Also, Eclipse does not seen to recognize it, so I was able to get things working without it.
Thomas Haskes wrote on Wed, 23 September 2009 07:13 | Note that the classloader that you provide the emf with must be able to
see your persistence.xml.
|
Here was the problem. My persistence code sits in a "helper" class in another plug-in which handles some housekeeping. I intend on reusing this class in different applications in the future to simplify life. The persistence.xml was declared ok and was visible to my RC app, but the classloader my "helper" class was using was the problem. While the classloader it was using when running under JUnit was ok and found my persistence.xml, it was using the wrong classloader when running under my RC app. I now pass the correct classloader to my "helper" class and all is OK.
Thanks again for your help!
Matthew
|
|
| |
Goto Forum:
Current Time: Thu Jan 23 01:53:29 GMT 2025
Powered by FUDForum. Page generated in 0.02880 seconds
|