I have the following error:
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 ?
The problem is
demo-persistence-jpa
needs both javax.persistence
and org.hibernate.proxy
. org.hibernate.proxy
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 :
javax.persistence
>= 2.1demo-persistence-jpa
import javax.persistence
< 2.1