融合7.0 JPA persistence.xml模式正在等待名称空间处理程序

时间:2019-10-22 16:03:05

标签: jbossfuse fuseesb

我已经尝试了JPA 2.1注册表persistence_1_0.xsd,persistence_2_0.xsd,persistence_2_1.xsd中的所有名称空间处理程序。结果,它们都不起作用并抛出错误。

2.0,2.1 正在等待名称空间处理程序[http://xmlns.jcp.org/xml/ns/persistence] 1.0 正在等待名称空间处理程序[http://java.sun.com/xml/ns/persistence]

让我知道问题的原因。

非常感谢。

1 个答案:

答案 0 :(得分:0)

如果您检查:

karaf@root()> feature:info jpa
Feature jpa 2.7.2
Description:
  OSGi Persistence Container
Details:
  JPA implementation provided by Apache Aries JPA 2.x. NB: this feature doesn't provide the JPA engine, you have to install one by yourself (OpenJPA for instance)
Feature has no configuration
Feature has no configuration files
Feature has no dependencies.
Feature contains followed bundles:
  mvn:org.apache.aries.jpa.javax.persistence/javax.persistence_2.1/2.7.2
  mvn:org.apache.geronimo.specs/geronimo-jta_1.1_spec/1.1.1.redhat-2 (overriden from mvn:org.apache.geronimo.specs/geronimo-jta_1.1_spec/1.1.1)
  mvn:org.osgi/org.osgi.service.jdbc/1.0.0
  mvn:org.apache.felix/org.apache.felix.coordinator/1.0.2 start-level=30
  mvn:org.apache.aries.jpa/org.apache.aries.jpa.api/2.7.2 start-level=30
  mvn:org.apache.aries.jpa/org.apache.aries.jpa.container/2.7.2 start-level=30
  mvn:org.apache.aries.jpa/org.apache.aries.jpa.support/2.7.2 start-level=30
Feature contains followed conditionals:
Conditional(aries-blueprint) has no configuration
Conditional(aries-blueprint) has no configuration files
Conditional(aries-blueprint) has no dependencies.
Conditional(aries-blueprint) contains followed bundles:
  mvn:org.apache.aries.jpa/org.apache.aries.jpa.blueprint/2.7.2 start-level=30

您会看到 NB:此功能不提供JPA引擎,您必须自己安装一个(例如OpenJPA)。这个描述似乎很旧。您需要实际的JPA提供程序,例如:

karaf@root()> feature:info hibernate
Feature hibernate 5.3.10.Final-redhat-00001
Description:
  Hibernate JPA engine support
Feature has no configuration
Feature has no configuration files
Feature depends on:
  wrap 0.0.0
  hibernate-orm 5.3.10.Final-redhat-00001
Feature contains followed bundles:
  mvn:net.bytebuddy/byte-buddy/1.9.5.redhat-00001 (overriden from mvn:net.bytebuddy/byte-buddy/1.9.5.redhat-00001)
Feature has no conditionals.

(来自Fuse的捆绑软件版本低于7.0)。

因此,请另外安装hibernate功能:

karaf@root()> feature:install hibernate

karaf@root()> la -l|grep hibernate
249 │ Active   │  80 │ 5.0.4.Final-redhat-00001  │ mvn:org.hibernate.common/hibernate-commons-annotations/5.0.4.Final-redhat-00001
250 │ Active   │  80 │ 5.3.10.Final-redhat-00001 │ mvn:org.hibernate/hibernate-core/5.3.10.Final-redhat-00001
251 │ Active   │  80 │ 5.3.10.Final-redhat-00001 │ mvn:org.hibernate/hibernate-osgi/5.3.10.Final-redhat-00001

编辑2019-11-07:

我检查了一下(即将推出的保险丝7.5,但应该适用于7.0),发现存在问题。

如果您检查:

karaf@root()> ls PersistenceProvider
[javax.persistence.spi.PersistenceProvider]
-------------------------------------------
 javax.persistence.provider = org.hibernate.jpa.HibernatePersistenceProvider
 service.bundleid = 250
 service.id = 468
 service.scope = bundle
Provided by : 
 hibernate-osgi (250)
Used by: 
 Apache Aries JPA Specification 2.1 API (244)
 Camel Content-Based Router Example [EXAM-PREP] (256)

您会看到Hibernate注册了org.hibernate.jpa.HibernatePersistenceProvider个JPA提供程序。

您已添加(在META-INF/persistence.xml中):

<provider>org.hibernate.ejb.HibernatePersistence</provider>

您应该删除此提供程序或使用org.hibernate.jpa.HibernatePersistenceProvider,因为它会影响org.apache.aries.jpa.container.impl.PersistenceProviderTracker#createFilter为您的捆绑软件创建的OSGi过滤器。因此,这就是您未注册EMF的原因。

通过此更改,我发现它可以正常工作

karaf@root()> ls EntityManagerFactory
[javax.persistence.EntityManagerFactory]
----------------------------------------
 hibernate.connection.pool_size = 25
 hibernate.dialect = org.hibernate.dialect.DerbyDialect
 hibernate.hbm2ddl.auto = create
 hibernate.show_sql = true
 javax.persistence.jdbc.driver = org.apache.derby.jdbc.EmbeddedDriver
 javax.persistence.jdbc.url = jdbc:derby:memory:order;create=true
 javax.persistence.jdbc.user = sa
 osgi.unit.name = camel
 osgi.unit.provider = org.hibernate.jpa.HibernatePersistenceProvider
 osgi.unit.version = 4.1.4
 service.bundleid = 256
 service.id = 501
 service.scope = singleton
Provided by : 
 Camel Content-Based Router Example [EXAM-PREP] (256)
Used by: 
 Camel Content-Based Router Example [EXAM-PREP] (256)