0
votes

I am trying to add Hibernate as a dependency of my OSGi bundle using Maven. In my POM file I have:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-osgi</artifactId>
    <version>4.3.6.Final</version>
</dependency>

However, when I ran that I got an error:

org.osgi.framework.BundleException: Unresolved constraint in bundle org.hibernate.core [8]: Unable to resolve 8.0: missing requirement [8.0] osgi.wiring.package; (&(osgi.wiring.package=javax.transaction.xa)(version>=1.1.0)(!(version>=2.0.0))) [caused by: Unable to resolve 15.0: missing requirement [15.0] osgi.wiring.package; (osgi.wiring.package=javax.enterprise.context)]

So I added another dependency for javax.enterprise.context:

<dependency>
    <groupId>javax.enterprise</groupId>
    <artifactId>cdi-api</artifactId>
    <version>1.2</version>
</dependency>

Which solved the previous error but lead to another error:

Auto-properties install: file:///path/to/project/hibernate/target/bundles/javax.inject-1.jar (org.osgi.framework.BundleException: Could not create bundle object. - java.lang.IndexOutOfBoundsException)

And now, I am unable to solve this one or even find out what causes it. I use Apache Felix.

1

1 Answers

3
votes

That won't work. If you want to use Hibernate in OSGi you'll need some bundle that actually provide the needed interfaces in osgi bundles. For your current use-case I'd suggest using Karaf and install the JPA/JTA features of Apache Aries. Karaf is a OSGi container with lots of dependencies resolved and easy to install features. To use Karaf with JPA just do the following

features:install jpa
features:install jta
features:install hibernate

with that you should be set to use hibernate in an osgi container. Another approach would be to install all required bundles to run blueprint osgi with hibernate and jpa/jta support yourself. For a list of those take a look at the corresponding features files. Available at Karaf