Try using Bundle-ClassPath like this in your manifest
Bundle-ClassPath: ., /location/of/persistence.xml
Try using Bundle-ClassPath like this in your manifest
Bundle-ClassPath: ., /location/of/persistence.xml
The Meta-inf directory is not on the classpath. This should work by simply placing it under your src dirctory. If you want it in a separate location, then you will have to specify the Bundle-Classpath to include that directory. By default the classpath is '.'.
I am not using persistence.xml but hibernate.cfg.xml which is similar:
src/main/resource/hibernate/hibernate.cfg.xml
In my Activator I am getting the file via the bundle context: Here is some example code how I do it and also reference that file:>
private void initHibernate(BundleContext context) { try { final AnnotationConfiguration cfg = new AnnotationConfiguration(); cfg.configure(context.getBundle().getEntry("/src/main/resource/hibernate/hibernate.cfg.xml")); sessionFactory = cfg.buildSessionFactory(); } catch (Exception e) { // TODO Auto-generated catch block } }
As you can see line which gets the config file is:
context.getBundle().getEntry("/src/main/resource/hibernate/hibernate.cfg.xml")
As you can see my hibernate.cfg.xml is NOT inside the META-INF folder. It is just in the root folder under /src/......
Hope that helps.
Christoph
Use EclipseLink and forget about Hibernate and other implementations, because :
You'll have to play with the classloader too much... Thread.currentThread().setContextClassLoader(...)
You'll be tempted to set the bundle-classpath attribute and add dependencies manually instead of installing jar bundles.
You'll get provider not found errors or you might not be able to find persistence.xml
All the above efforts might not work after many attempts.
However, with EclipseLink it's a no brainer, the implementation was designed to work out of the box in an OSGI environment and there aren't any class loading headaches.
You need to have the directory that contains META-INF on the classpath. Each directory is searched for META-INF and if found, then persistence.xml is searched for.
If you put "META-INF" on the classpath, then you'd need another META-INF in that directory.
hi ,
I have been trying to run a simple program to call the database using a bundle in eclipse.I have included the hibernate.cfg.xml and the mapping file too but it still its saying that : java.lang.NoClassDefFoundError: org/dom4j/DocumentException
even though i have included the dom4j.jar in the bundle build path
please suggest some work around and ways to go about it
I'm getting the same problem.
I think eclipse link is the best option to use in a OSGi Environment. And there are no problem because you will work basically with the JPA implementation. When you need to move to Hibernate, just replace persintece.xml config and some libs.
Hello,
you need to set property (for hibernate it will be different):
javax.persistence.provider=org.apache.openjpa.persistence.PersistenceProviderImpl
for call:
Persistence.createEntityManagerFactory(entityManagerFactoryName, properties)
to make it work.
And as mentioned before, you need classloader wrapping. You can use ClassloaderEntityManager from https://issues.apache.org/jira/browse/OPENJPA-1783 to do that.
Regards