java - 两个依赖链 OSGI

标签 java hibernate jpa osgi apache-servicemix

我有以下错误:

enter image description here

在文本中:

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)]

如您所见,问题出在我的包 demo-persistence-jpa imports 包 `javax.persistence 可通过两条链获得,我明白这一点

我不明白的地方:

  • 我的包在 version>=2.1.0

    范围内导入
  • org.hibernate.proxy(version>=1.0.0)(!(version>=2.0.0))) 范围内导入,所以应该没有问题

  • 我的包导入 org.hibernate.proxy

所以应该没有问题,因为我的bundle需要的版本和org.hibernate.proxy

需要的版本不一样

还是我弄错了?

最佳答案

问题是

  • demo-persistence-jpa两者都需要 javax.persistenceorg.hibernate.proxy .
  • hibernate 包导出 org.hibernate.proxy
  • hibernate bundle 声明它 uses:=javax.persistence

对于解析器,这意味着无论谁使用 hibernate 包中的包,都必须连接到提供 javax.persistence 的完全相同的包/类加载器。 hibernate 包连接到。

如果运行时无法确保每个连接到不同的包/类加载器,您将得到 ClassCastException hibernate bundle 中的某些东西返回给你一个来自 javax.persistence 的对象因为它将来自不同的类加载器。

在上述情况下,解析器无法确保,因为 hibernate bundle 需要 javax.persistence版本低于 2.0 和 demo-persistence-jpa需要版本高于2.1!

解决方案是:

  • 使用与javax.persistence 一起工作的较新版本的hibernate(假设有一个) >= 2.1
  • 制作demo-persistence-jpa进口 javax.persistence < 2.1

关于java - 两个依赖链 OSGI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40784855/

相关文章:

java - 建立Gradle本地依赖性

java - 位图在android中总是返回null

java - 等待函数有逻辑错误

java - Hibernate/JPA 混合 ID 生成策略

java - 如何解决 hibernate 中的目标未映射类错误?

java - 执行计数语句时 JPA 和 Hibernate 库出现问题

java - jsp页面中的Applet(Eclipse)

java - 有没有办法以动态方式映射具有相同表名的多个数据库?

java - Hibernate不允许删除子元素

java - EclipseLink 在 Oracle DB 上生成重复的主键