|
Re: using EclipseLink in an Eclipse rich client plugin [message #490263 is a reply to message #489977] |
Thu, 08 October 2009 02:53   |
Eclipse User |
|
|
|
Hi Alan,
if you are using the OSGi Version of Eclipselink, there are some
configurations to make, but it is hard to figure out what is missing
without knowing more details of how the bundle structure of your
application looks like. Anyway here some thoughts that might help.
To make things easier, it helps to put all entities, the persistence.xml
and all other persistence related stuff in one bundle. This is not
always neccessary, but for a first try it eases things up.
The first you need to do is to pass the right classloader to the
EntityManagerFactory and the EntityManager. If everything resides in the
same bundle, you can use the classloader of the Activator of that
bundle. This is neccessary because the emf and the em need to see the
persistence.xml and the entity classes. Here is an example:
HashMap<String, Object> props = new HashMap<String, Object>();
props.put(PersistenceUnitProperties.CLASSLOADER, Activator.class
.getClassLoader());
entityManagerFactory = Persistence
.createEntityManagerFactory("your_pu", props);
For the EntityManager:
Map<String, Object> props = new HashMap<String, Object>();
props.put(PersistenceUnitProperties.CLASSLOADER, Activator.class
.getClassLoader());
EntityManager em = entityManagerFactory.createEntityManager(props);
I think you can use any other class from your application bundle where
the persistence.xml is, too (instead of the Activator).
The next thing is that you need to specify the PersistenceUnit in the
MANIFEST.MF file using this line:
JPA-PersistenceUnits: your_pu
Hope this helps you, if not, please post some more information about
your setup, I'm sure we can get it working.
Greets from Bochum, Germany
Tom
alan kemp schrieb:
> I have created an EclipseLink mySQL test harness with a POJO application
> and had no problems. now I would like to create an Eclipse plugin that
> uses EclipseLink. I am using Eclipse for RCP Plugin Developers. For
> dependencies I have required the persistence core plugin libraries as
> provided by Eclipse. My persistence xml file is in the METADATA
> directory. However I am getting the error: No persistence provider for
> EntityManager named XXXX. Anyone had any experience or have suggestions
> for this .. I am out of ideas today.
|
|
|
|
Re: using EclipseLink in an Eclipse rich client plugin [message #490566 is a reply to message #490363] |
Fri, 09 October 2009 04:27   |
Eclipse User |
|
|
|
There is something I forgot, you need to load the pesistence bundles in
the right order, because the org.eclipse.persistence.jpa bundle
registers the PersistenceProvider as a service. So you need to be sure
that the service is there before your application bundle starts.
Second thing is that I had to start the org.eclipse.persistence.antlr
bundle, too. I'm not sure whether that dpands on my setup, but I think
it's worth a try.
Try the following.
Set a default start level of 5.
We need the javax.persistence bundle to start at first, so set a
startlevel of 3.
Next org.eclipse.persistence.jpa should be started -> start level 4
Leave all the rest at startlevel 5.
Have a look for the following output on the osgi console:
2009-10-09 10:25:11,328 INFO [STDOUT] Persistence bundle starting...
2009-10-09 10:25:11,329 INFO [STDOUT] Persistence bundle started.
2009-10-09 10:25:25,565 INFO [STDOUT] ProviderTracker: New service
detected...
2009-10-09 10:25:25,565 INFO [STDOUT] ProviderTracker: Added service
org.eclipse.persistence.jpa.osgi.PersistenceProviderOSGi
If you don't see the output, make sure you set the -console -consolelog
arguments in the launch configurations. If you still don't see it,
you've at least identified the problem, the PersistenceProvider service
is not registered.
Greets,
Tom
alan kemp schrieb:
> Hello from sunny warm Florida, USA 8)
> From my test this morning I see that the code is failing at
> createEntityManagerFactory() even though I added the
> JPA-PersistenceUnits entry to the plugin manifest and added the class
> loader to createEntityManager().
> here are my required bundles:
>
> Require-Bundle: org.eclipse.ui,
> org.eclipse.core.runtime,
> org.eclipse.persistence.core;bundle-version="1.1.2",
> org.eclipse.persistence.jpa;bundle-version="1.1.2",
> org.eclipse.persistence.asm;bundle-version="1.1.2",
> javax.persistence;bundle-version="1.99.0"
>
> environment is Eclipse Galileo for Plugin Developers. the project is a
> RCP plugin with a View and Editor. jre version is 1.5.0_11. the code was
> generated by eclipse and the createEntityManager section is in
> view.initialize(). thanks for the help Tom.
>
>
>
>
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06018 seconds