如果你检查:
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
您会看到注意:此功能不提供 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:
我检查了(即将推出的 Fuse 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)