I'd like to create one Bundle that is able to use Java Persistence. To achieve this, I've created a plugin project within Eclipse. In my project, I've created a persistence.xml file into META-INF. I've aslo added in my MANIFEST.mf (into the depencies) those 3 packages :
Then, in my Activator I use this lines to create an EntityManager :
factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
EntityManager em = factory.createEntityManager();
To execute my bundle, I've made a product configuration. When I run my product configuration, I got this error :
javax.persistence.PersistenceException: No Persistence provider for EntityManager named people
I've tried to move the location of my persistence.xml
without success. It seems that any package load the persistence.xml
file. Maybe, I don't import the right packages?
You can download my simple Bundle here : download
Could you help me to find a solution or a clue?
I've solved my problem. I only had to put in the classpath of the manifest this packages : - persistence.jar - eclipselink.jar - mysql-connector.jar
Thanks
Try adding this tag in the persistence.xml
:
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
I was getting the same error in a simple project running in Eclipse.
It turns out that adding the META-INF directory (containing persistence.xml) to my class path was the wrong thing to do.
You have to have its containing dir (or jar) on the class path. From the EclipseLink 2.5.1 sources:
/**
* Search the classpath for persistence archives. A persistence archive is
* defined as any part of the class path that contains a META-INF directory
* with a persistence.xml file in it. Return a list of {@link Archive}
* representing the root of those files. It is the caller's responsibility
* to close all the archives.
*
* @param loader the class loader to get the class path from
*/
public static Set<Archive> findPersistenceArchives(ClassLoader loader){
// allow alternate persistence location to be specified via system property. This will allow persistence units
// with alternate persistence xml locations to be weaved
String descriptorLocation = System.getProperty(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML, PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML_DEFAULT);
return findPersistenceArchives(loader, descriptorLocation);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With