首页 > 解决方案 > fuse 7.0 JPA persistence.xml 模式正在等待命名空间处理程序

问题描述

我已经尝试了 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]

让我知道问题的原因。

提前谢谢了。

标签: jbossfusefuseesb

解决方案


If you check:

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

You'll see NB: this feature doesn't provide the JPA engine, you have to install one by yourself (OpenJPA for instance). This description seems old. You need actual JPA provider, like:

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.

(versions of bundles from Fuse newer than 7.0).

So please install additionally hibernate feature:

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

EDIT 2019-11-07:

I checked (upcoming Fuse 7.5, but should be valid for 7.0) and found the problem you have.

If you check:

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)

you'll see there's org.hibernate.jpa.HibernatePersistenceProvider JPA provider registered by Hibernate.

You've however added (in META-INF/persistence.xml):

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

You should either remove this provider or use org.hibernate.jpa.HibernatePersistenceProvider because it affects an OSGi filter created by org.apache.aries.jpa.container.impl.PersistenceProviderTracker#createFilter for your bundle. So that's the reason why you didn't have EMF registered.

With this change, I found it works:

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)

推荐阅读