1

I'm writing hibernate dto-mapping osgi bundle (for glassfish), and this bundle didn't see resourses from classpath.

Manifest file:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Model
Bundle-SymbolicName: com.test.spm.model
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: com.test.spm.model.Activator
Bundle-Vendor: TEST
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: org.osgi.framework;version="1.3.0"
Require-Bundle: org.hibernate.core;bundle-version="4.1.7"
Export-Package: com.test.spm.model,
 com.test.spm.model.dto,
 com.test.spm.model.dto.base,
 com.test.spm.model.util
Bundle-ClassPath: .,
 lib/sqljdbc4.jar

Cant access files from sqljdbc4.jar, error:

Caused by: java.lang.ClassNotFoundException: Could not load requested class : com.microsoft.sqlserver.jdbc.SQLServerDriver

But this library exists in exported jar file.

Also i cant access hibernate configuration file, and mapping files through class-path (class not found and resourse not found exceptions too). But next code works:

            sessionFactory = new Configuration().configure(HibernateUtil.class.getClassLoader().getResource("hibernate.cfg.xml"))
                    .addURL(HibernateUtil.class.getClassLoader().getResource("mapping/Project.hmb.xml"))
                    .buildSessionFactory();

I tried to invoke

System.out.println(HibernateUtil.class.getClassLoader().getResource("hibernate.cfg.xml")); 

and see this in sys out:

bundle://376.0:1/hibernate.cfg.xml

Googled for bundle classpath options, but my manifest seems ok. Need i some specific bundle classpath properties to make my bundle see classpath resourses, or what? Thanx for help!

Björn Pollex
  • 75,346
  • 28
  • 201
  • 283
Peter
  • 305
  • 3
  • 18

1 Answers1

3

Hibernate can't find any resources in an other bundle than that one where the jar library is included in. Hibernate does not know the OSGI manifest files and it ignores them, so it doesn't matter if your manifest file is correct or not.

Please see my answer in this thread, the solutions which I've given there should also work for your problems.

Community
  • 1
  • 1
Johanna
  • 5,223
  • 1
  • 21
  • 38
  • You are totally right, i added hibernate libs to this bundle and all works right! But can u explain me next thing: one of my last projects was RCP-project (OSGi (equinox) bundled plugin system too), and i splited hibernate libs plugin separate of dto-mapping plugin and all worked fine! What is different in RCP bundle system and in this my problem? – Peter Sep 21 '12 at 11:18
  • I can't explain that because I don't know RCP programming and I don't know how your project was installed. The main problem is, the paths in the resources which are specified in hibernate.cfg.xml are relative to the main directory of the bundle which is executed (i. e. the bundle where the hibernate libraries are in), and there is no standard way in Hibernate to specify a path into an other bundle. – Johanna Sep 21 '12 at 13:05