Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » using EclipseLink in an Eclipse rich client plugin
icon5.gif  using EclipseLink in an Eclipse rich client plugin [message #489977] Tue, 06 October 2009 17:34 Go to next message
alan kemp is currently offline alan kemp
Messages: 17
Registered: October 2009
Junior Member
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 #490263 is a reply to message #489977] Thu, 08 October 2009 06:53 Go to previous messageGo to next message
Thomas Haskes is currently offline Thomas Haskes
Messages: 147
Registered: July 2009
Senior Member
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 #490363 is a reply to message #490263] Thu, 08 October 2009 13:02 Go to previous messageGo to next message
alan kemp is currently offline alan kemp
Messages: 17
Registered: October 2009
Junior Member
Hello from sunny warm Florida, USA Cool

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.



Re: using EclipseLink in an Eclipse rich client plugin [message #490566 is a reply to message #490363] Fri, 09 October 2009 08:27 Go to previous messageGo to next message
Thomas Haskes is currently offline Thomas Haskes
Messages: 147
Registered: July 2009
Senior Member
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.
>
>
>
>
Re: using EclipseLink in an Eclipse rich client plugin [message #490692 is a reply to message #490566] Fri, 09 October 2009 17:45 Go to previous messageGo to next message
alan kemp is currently offline alan kemp
Messages: 17
Registered: October 2009
Junior Member
No Message Body

[Updated on: Fri, 09 October 2009 18:53]

Report message to a moderator

icon14.gif  Re: using EclipseLink in an Eclipse rich client plugin [message #490709 is a reply to message #490566] Fri, 09 October 2009 18:52 Go to previous messageGo to next message
alan kemp is currently offline alan kemp
Messages: 17
Registered: October 2009
Junior Member
ok happy today. i dropped the eclipselink jar files and jdbc driver in the bundle root and added to class path instead of requiring the the plug-ins. i'm sure now i will have more JPA and RCP questions but for now thanks for the help Cool
Re: using EclipseLink in an Eclipse rich client plugin [message #492524 is a reply to message #490709] Tue, 20 October 2009 16:05 Go to previous messageGo to next message
alan kemp is currently offline alan kemp
Messages: 17
Registered: October 2009
Junior Member
ok not so happy anymore. the plugin worked as long as I was executing it from inside the eclipse IDE. as soon as I deployed the plugin it was the same error again: No persistence provider for EntityManager named XXXX Shocked
Re: using EclipseLink in an Eclipse rich client plugin [message #492690 is a reply to message #492524] Wed, 21 October 2009 12:22 Go to previous messageGo to next message
Shaun Smith is currently offline Shaun Smith
Messages: 197
Registered: July 2009
Senior Member
There are examples of how to run EclipseLink in OSGi and RCP on the wiki: http://wiki.eclipse.org/EclipseLink/Examples/OSGi

The key difference between the OSGi and RCP case is how the EntityManagerFactory is created--the problem you're dealing with. In a "pure" OSGi environment EclipseLink does some magic using services and a bundle listener to discover and register persistence units so that Persistence.createEntityManagerFactory() works. It could probably do the same in RCP but we haven't reconciled the use of services and bundle listeners with how RCP applications boot.

So in an RCP application (as in the wiki example) you obtain an EntityManagerFactory by calling new
PersistenceProvider().createEntityManagerFactory(properties)

PersistenceProvider is org.eclipse.persistence.jpa.PersistenceProvider. Essentially this approach goes directly to EclipseLink and avoids the provider lookup mechanism of JPA (which is service based in EclipseLink OSGi).

Note that you do need to provide a classloader that can see your persistence unit resources and Entities in the properties passed to createEntityManagerFactory. Here's an excerpt from the RCP 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;
    }


--Shaun
Re: using EclipseLink in an Eclipse rich client plugin [message #533013 is a reply to message #492690] Tue, 11 May 2010 21:05 Go to previous messageGo to next message
Tan-Vinh Nguyen is currently offline Tan-Vinh Nguyen
Messages: 2
Registered: May 2010
Junior Member
Thank you very much Shaun!

Your hint and explanation lead me to the right spot. That problem drives me nuts. That information should be in the WIKI! After I set the property CLASSLOADER to
Activator.getClass().getClassLoader()
it works!
Re: using EclipseLink in an Eclipse rich client plugin [message #537535 is a reply to message #492690] Wed, 02 June 2010 19:21 Go to previous messageGo to next message
alan kemp is currently offline alan kemp
Messages: 17
Registered: October 2009
Junior Member
Shaun Smith wrote on Wed, 21 October 2009 08:22
So in an RCP application (as in the wiki example) you obtain an EntityManagerFactory by calling new
PersistenceProvider().createEntityManagerFactory(properties)

PersistenceProvider is org.eclipse.persistence.jpa.PersistenceProvider. Essentially this approach goes directly to EclipseLink and avoids the provider lookup mechanism of JPA (which is service based in EclipseLink OSGi).
--Shaun


out of curiosity I did try this with my RCP plugin and this does not work for me. I put your code into the Activator.start method .. does this sound ok? if not where should this be done? I need some magic for my application .. thanks.

when I execute this line: new PersistenceProvider().createEntityManagerFactory("test", properties) .. I get null instead of a factory. I checked and the classloader can see persistence.xml and entities. also the RCP example is headless and mine is an RCP application with a view.



[Updated on: Thu, 03 June 2010 18:57]

Report message to a moderator

icon5.gif  Re: using EclipseLink in an Eclipse rich client plugin [message #540605 is a reply to message #537535] Wed, 16 June 2010 16:22 Go to previous messageGo to next message
alan kemp is currently offline alan kemp
Messages: 17
Registered: October 2009
Junior Member
anybody?? how come my app doesn't work as advertised?? thanks. again i have it working in a swing and pojo application .. why so tough with eclipse plugin?? is there no way to know why the factory is failing??

[Updated on: Wed, 16 June 2010 18:16]

Report message to a moderator

Re: using EclipseLink in an Eclipse rich client plugin [message #541155 is a reply to message #540605] Fri, 18 June 2010 13:31 Go to previous message
Shaun Smith is currently offline Shaun Smith
Messages: 197
Registered: July 2009
Senior Member
Hi Alan,

Perhaps the classloader you're passing as a property to createEntityManagerFactory can't see all of the necessary classes? I've just been updating the RCP example on the wiki for the imminent EclipseLink 2.1 release.

Can you take a look at this and try running the example? Comparing the manifests in the example to yours may uncover the problem.

Also, take a look at the note on importing javax.persistence in EclipseLink 2.1 as we've made changes to align with the OSGi Enterprise specification for JPA.

--Shaun
Previous Topic:Change table name at runtime
Next Topic:Unsatisfied import package javax.activation_0.0.0
Goto Forum:
  


Current Time: Tue Sep 30 18:07:40 GMT 2014

Powered by FUDForum. Page generated in 0.03798 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software