tags:

views:

937

answers:

1

I am trying to create an Eclipse application that uses JPA for persistence.
I am trying to use EclipseLink as my provider (more specific org.eclipse.persistence.jpa.PersistenceProvider) and Derby as my database.
Currently I have an Eclipse JPA Project that deals with all the database communication and defines the model entities. This product is being unit tested and it all works.

The idea is that my Eclipse application uses this project to get the model entities that it uses.
The problem is that as soon as I try to create an EntityManager, I get a "No Persistence provider" exception.

I have tried referencing the JPA project directly, or first exporting it to a jar and depending on that. Neither worked.

Now as far as I can guess, this either means that it does not see my persistence.xml or that the persistence provider is not in my classpath.

The persistence file is in the META-INF directory in the root of my jar, so hopefully it should be picked up. I have also added the following to the MANIFEST.MF of the application plugin:

 javax.persistence;bundle-version="1.99.0",
 org.eclipse.persistence.antlr;bundle-version="1.1.2",
 org.eclipse.persistence.asm;bundle-version="1.1.2",
 org.eclipse.persistence.core;bundle-version="1.1.2",
 org.eclipse.persistence.jpa;bundle-version="1.1.2"

This would hopefully cause the needed classes to be available.

Can anyone see what I am missing? Is there a way to see which of the two problems it might be? Is it one of these problems?

Thanks for any help.

+1  A: 

Note: the current wiki example is still deprecated (since August 2008...)

You can see in their updated example a launcher (with list of relevant plugins)

Their MANIFEST.MF looks like:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Application Plug-in
Bundle-SymbolicName: org.eclipse.persistence.example.jpa.rcp.comics; singleton:=true
Bundle-Version: 1.0.0
Require-Bundle: org.eclipse.core.runtime,
 org.eclipse.ui,
 org.eclipse.persistence.jpa,
 system.bundle,
 org.eclipse.persistence.example.jpa.comics.model.annotated;bundle-version="1.0.0",
 javax.persistence;bundle-version="1.99.0",
 org.eclipse.persistence.antlr;bundle-version="0.1.0"
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ClassPath: .
Import-Package: org.apache.derby.jdbc

May be using that example could help you find what is incorrect in your application?

VonC
Yes, thank you, in there I could see what the problem was. I used to create the entity manager factory withPersistence.createEntityManagerFactory(UNIT_NAME);which relies on the persistence.xml. This does not work, but the following does:new PersistenceProvider().createEntityManagerFactory( UNIT_NAME, properties)Where properties is a hashmap and persistence provider gets determined by your import statements and not the persistence.xml.And lastly, it looks like you must use org.eclipse.persistence.jpa.osgi.PersistenceProvider as your provider.