JPA和Apache Aries:持久性单元未解析的依赖性

时间:2015-06-18 07:40:00

标签: java jpa osgi blueprint-osgi 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>

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

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

你能帮我发现这里遗漏的东西吗?调试这种情况的最佳方法是什么?

感谢。

2 个答案:

答案 0 :(得分:2)

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

有两个可能的原因。完全找不到persitence单元,或者为它创建EntityManagerFactory时出错。

如果您在日志中看不到其他错误,我怀疑根本不会识别持久性单元。请检查您的实体包的清单中是否包含Meta-Persistence属性:META-INF / persistence.xml。

另一个可能的问题可能是您在需要它们的同一个包中创建DataSource服务。由于只有在找到EntityManageFactory服务时才会出现蓝图,因此可能永远不会启动DataSource。最好把它们放在另一束中。甚至可以使用pax-jdbc-config更好地定义DataSource。

答案 1 :(得分:1)

问题是由于我的运行时中有大量丢失的包。要解决这个问题,只需查看Apache Aries Samples中的博客示例项目,并在我的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