JPA 和 Apache Aries:持久性单元未解决的依赖关系



我正在尝试为 mysql 配置数据源,并在 Apache Aries 之上配置相应的持久性包。这是数据源的蓝图文件

<bean id="mysqlDataSource" class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource">
    <property name="url" value="jdbc:mysql://matteos-mbp:3306/" />
    <property name="user" value="root" />
    <property name="password" value="root" />
    <property name="databaseName" value="testDBBlueprint" /> 
    <property name="createDatabaseIfNotExist" value="true" />
</bean>
<bean id="mysqlXADataSource" class="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource">
    <property name="url" value="jdbc:mysql://matteos-mbp:3306/" />
    <property name="user" value="root" />
    <property name="password" value="root" />
    <property name="databaseName" value="testDBBlueprint" /> 
    <property name="createDatabaseIfNotExist" value="true" />
</bean>
<service ref="mysqlDataSource" interface="javax.sql.DataSource">
    <service-properties>
        <entry key="osgi.jndi.service.name" value="jdbc/ddauthdb" />
    </service-properties>
</service>
<service ref="mysqlXADataSource" interface="javax.sql.XADataSource">
    <service-properties>
        <entry key="osgi.jndi.service.name" value="jdbc/xaddauthdb" />
    </service-properties>
</service>

这些是实体/持久性捆绑包(捆绑包com.mycompany.jpa.auth.entities)的持久性.xml和蓝图.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<persistence
    xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
    http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
    version="2.0">
    <persistence-unit name="ddauth">
        <jta-data-source>
osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/xaddauthdb)      
</jta-data-source>
        <non-jta-data-source>
            osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/ddauthdb)
        </non-jta-data-source>
        <class>com.mycompany.persistence.users.TestUser</class>
        <exclude-unlisted-classes>true</exclude-unlisted-classes>
        <properties>
            <property
                name="openjpa.jdbc.SynchronizeMappings"
                value="buildSchema(ForeignKeys=true)" />
        </properties>
    </persistence-unit>
</persistence>

<?xml version="1.0" encoding="UTF-8"?>
<blueprint 
    xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.0.0"
    xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0">
    <bean id="userService" class="com.mycompany.persistence.users.UserServiceImpl">
        <tx:transaction method="*" value="Required" />
        <jpa:context property="entityManager" unitname="ddauth"/> 
    </bean>
    <bean
        id="populator"
        class="com.mycompany.persistence.users.Populator"
        init-method="populate"
        activation="eager"    >
        <property
            name="userService"
            ref="userService" />
    </bean>
    <service ref="userService" interface="com.mycompany.users.api.UserService" />
</blueprint>

我得到的错误是

org.ops4j.pax.logging.pax-logging-api[org.apache.aries.blueprint.container.BlueprintContainerImpl] : Unable to start blueprint container for bundle com.mycompany.jpa.auth.entities due to unresolved dependencies [(&(&(org.apache.aries.jpa.proxy.factory=true)(osgi.unit.name=ddauth))(objectClass=javax.persistence.EntityManagerFactory))]
java.util.concurrent.TimeoutException
    at org.apache.aries.blueprint.container.BlueprintContainerImpl$1.run(BlueprintContainerImpl.java:336)
    at org.apache.aries.blueprint.utils.threading.impl.DiscardableRunnable.run(DiscardableRunnable.java:48)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
org.ops4j.pax.logging.pax-logging-api[org.apache.aries.blueprint.container.BlueprintEventDispatcher] : Sending blueprint container event BlueprintEvent[type=FAILURE, dependencies=[(&(&(org.apache.aries.jpa.proxy.factory=true)(osgi.unit.name=ddauth))(objectClass=javax.persistence.EntityManagerFactory))], exception=null] for bundle com.mycompany.jpa.auth.entities

我的运行时如下:

START LEVEL 1
   ID|State      |Level|Name
    0|Active     |    0|OSGi System Bundle (3.10.2.v20150203-1939)
    1|Active     |    1|aQute.xray.plugin (1.7.0.201403241317)
    2|Active     |    1|com.mycompany.db.mysql.auth (0.0.0.201506180714)
    3|Active     |    1|Oracle Corporation's JDBC Driver for MySQL (5.1.35)
    4|Active     |    1|Apache Commons Collections (3.2.1)
    5|Active     |    1|Apache Aries Blueprint Bundle (1.1.0)
    6|Active     |    1|Apache Aries Blueprint API (1.0.1)
    7|Active     |    1|Apache Aries Blueprint Core (1.4.2)
    8|Active     |    1|Aries JPA Container API (1.0.2)
    9|Active     |    1|Aries JPA Container blueprint integration for Aries blueprint (1.0.4)
   10|Active     |    1|Aries JPA Container (1.0.2)
   11|Active     |    1|Aries JPA Container Managed Contexts (1.0.4)
   12|Active     |    1|Apache Aries Proxy API (1.0.1)
   13|Active     |    1|Apache Aries Proxy Service (1.0.4)
   14|Active     |    1|Apache Aries Transaction Blueprint (1.0.2)
   15|Active     |    1|Apache Aries Transaction Manager (1.0.0)
   16|Active     |    1|Apache Aries Transaction Manager (1.1.1)
   17|Active     |    1|Apache Aries Util (1.1.0)
   18|Active     |    1|Commons Lang (2.6.0)
   19|Active     |    1|Commons Pool (1.6.0)
   20|Active     |    1|Apache CXF Core (3.1.1)
   21|Active     |    1|Apache CXF Runtime HTTP Transport (3.1.1)
   22|Active     |    1|Apache Felix Configuration Admin Service (1.8.0)
   23|Active     |    1|Apache Felix Gogo Command (0.14.0)
   24|Active     |    1|Apache Felix Gogo Runtime (0.12.1)
   25|Active     |    1|Apache Felix Gogo Shell (0.10.0)
   26|Active     |    1|Apache Felix Metatype Service (1.0.10)
   27|Active     |    1|Apache Felix Declarative Services (1.8.2)
   28|Active     |    1|Apache Felix Web Management Console (3.1.8)
   29|Active     |    1|Apache Geronimo JSR-317 JPA 2.0 Spec API (1.1.0)
   30|Active     |    1|geronimo-jta_1.1_spec (1.1.1)
   31|Active     |    1|OpenJPA Aggregate Jar (2.2.2)
   32|Active     |    1|Apache ServiceMix :: Bundles :: commons-dbcp (1.4.0.3)
   33|Active     |    1|XmlSchema Core (2.2.1)
   34|Active     |    1|Apache XBean OSGI Bundle Utilities (3.18.0)
   35|Active     |    1|Apache XBean :: Classpath Resource Finder (3.18.0)
   36|Active     |    1|hibernate-jpa-2.1-api (1.0.0.Final)
   37|Active     |    1|ASM all classes with debug info (5.0.3)
   38|Active     |    1|OPS4J Pax Logging - API (1.8.2)
   39|Active     |    1|OPS4J Pax Web - Jetty Bundle (4.1.2)
   40|Active     |    1|com.mycompany.jpa.auth.entities (0.0.0.201506180718)

你能帮我发现这里缺少什么吗?调试这种情况的最佳方法是什么?

谢谢。

该错误表示无法及时找到 EntityManagerFactory。

有两个可能的原因。要么根本找不到持久性单元,要么在为其创建实体管理器工厂时出错。

如果您在日志中没有看到其他错误,我怀疑根本无法识别持久性单元。请检查您的实体捆绑包的清单中是否具有属性元持久性:META-INF/持久性.xml。

另一个可能的问题可能是您在需要它们的同一捆绑包中创建数据源服务。由于蓝图仅在找到 EntityManageFactory 服务时才会出现,因此数据源可能永远不会启动。最好将它们放在另一个捆绑包中。使用 pax-jdbc-config 更好地定义数据源。

问题是由于我的运行时中缺少大量捆绑包。为了解决这个问题,只需查看 Apache Aries 示例中的博客示例项目,并将该运行时复制到我的 bnd 文件中就足够了。

我添加的捆绑包如下:

  • org.apache.aries.transaction.wrappers
  • org.apache.aries.jpa.container
  • org.apache.aries.jpa.container.context
  • org.apache.geronimo.specs.geronimo-j2ee-connector_1.5_spec
  • org.apache.geronimo.specs.geronimo-jpa_2.0_spec
  • org.apache.geronimo.specs.geronimo-jta_1.1_spec
  • org.apache.aries.jndi
  • org.apache.commons.pool
  • org.objectweb.asm.all
  • org.apache.servicemix.bundles.serp

相关内容

  • 没有找到相关文章

最新更新