two dependency chains OSGI
Asked Answered
C

2

5

I have the following error:

enter image description here

in text :

Error executing command: Error restarting bundles:
    Unable to start bundle 278: Uses constraint violation. Unable to resolve resource demo-persistence-jpa [demo-persistence-jpa [278](R 278.0)] because it is exposed to package 'javax.persistence' from resources javax.persistence [javax.persistence [248](R 248.0)] and org.apache.geronimo.specs.geronimo-jpa_2.0_spec [org.apache.geronimo.specs.geronimo-jpa_2.0_spec [266](R 266.0)] via two dependency chains.

Chain 1:
demo-persistence-jpa [demo-persistence-jpa [278](R 278.0)]

import: (&(osgi.wiring.package=javax.persistence)(version>=2.1.0))
 |
export: osgi.wiring.package: javax.persistence
javax.persistence [javax.persistence [248](R 248.0)]
Chain 2:
demo-persistence-jpa [demo-persistence-jpa [278](R 278.0)]
import: (osgi.wiring.package=org.hibernate.proxy)
 |
export: osgi.wiring.package=org.hibernate.proxy; uses:=javax.persistence
com.springsource.org.hibernate [com.springsource.org.hibernate [230](R   230.0)]
  import: (&(osgi.wiring.package=javax.persistence)(version>=1.0.0)(!(version>=2.0.0)))
 |
export: osgi.wiring.package: javax.persistence
org.apache.geronimo.specs.geronimo-jpa_2.0_spec   [org.apache.geronimo.specs.geronimo-jpa_2.0_spec [266](R 266.0)] Unresolved   requirements: [[demo-persistence-jpa [278](R 278.0)] osgi.wiring.package; (osgi.wiring.package=org.hibernate.proxy)]

as you can see the problem is my bundle demo-persistence-jpa imports the package `javax.persistence which is available via two chains, this I understand

what I don't understand :

  • My bundle imports within the range version>=2.1.0

  • org.hibernate.proxy imports within the range (version>=1.0.0)(!(version>=2.0.0))), so there should be no problem

  • My bundle imports org.hibernate.proxy

so there should be no problem, as the version required by my bundle is not the same as the one required by org.hibernate.proxy

or am I mistaken ?

Catarinacatarrh answered 24/11, 2016 at 11:9 Comment(2)
Could you please copy/paste the content of the error instead of providing a (non readable) screenshot?Stepson
i just added it in text, you can click on the image and it's more clear thoughCatarinacatarrh
J
5

The problem is

  • demo-persistence-jpa needs both javax.persistence and org.hibernate.proxy.
  • hibernate bundle exports org.hibernate.proxy
  • hibernate bundle states it uses:=javax.persistence

for the resolver this means that whoever uses packages from hibernate bundle has to be wired to the exact same bundle/classloader providing javax.persistence that hibernate bundle is wired to.

If the runtime din't ensure that and each was wired to different bundles/classloders you would get ClassCastException the moment something from hibernate bundle returns you an object from javax.persistence because it will be coming from different classloader.

In the case above, the resolver can no ensure that because hibernate bundle needs javax.persistence version to be lower than 2.0 and demo-persistence-jpa needs the version to be higher than 2.1!

The solution is to either :

  • use newer version of hibernate (assuming there is one) that works with javax.persistence >= 2.1
  • make demo-persistence-jpa import javax.persistence < 2.1
Jingoism answered 24/11, 2016 at 13:54 Comment(0)
B
0

I think the problem is that you have two bundles providing the spec in two different versions. This will not work. You have to make sure you can get along with just one jpa spec bundle.

How do you install hibernate and your own bundle? If you use the Apache karaf feature for hibernate it should work.

Bluebonnet answered 24/11, 2016 at 11:59 Comment(2)
Aren't we supposed to be able to have two different versions (or more) simultaneously ? here is a list of all the bundles installed : pastebin.com/raw/Y92CtFJa btw, I'm trying to follow your tutorial liquid-reality.de/display/liquid/2012/01/13/…Catarinacatarrh
Yes, assuming disjoint class spaces. But with the uses constraint (as mentioned by @milen-dyankov), you do not have a disjoint class space.Plowman

© 2022 - 2024 — McMap. All rights reserved.