【问题标题】:ServiceMix / JPA Integration - LocalContainerEntityManagerFactoryBean to type EntityManagerFactoryServiceMix / JPA 集成 - LocalContainerEntityManagerFactoryBean 输入 EntityManagerFactory
【发布时间】:2013-07-07 06:30:54
【问题描述】:

我对 ServiceMix / JPA / Camel / Spring 还很陌生。我正在尝试使用 camel-jpa 组件作为我的骆驼路线的一部分。我正在使用最新版本的 ServiceMix,即 4.5.1。这使用骆驼 2.10.4 和 spring 3.0.7。

在更新 OSGi 清单并将一些额外的模块部署到 servicemix 后,我陷入了以下堆栈跟踪:

org.osgi.service.blueprint.container.ComponentDefinitionException: Error setting property: PropertyDescriptor <name: entityManagerFactory, getter: class org.springframework.orm.jpa.JpaTransactionManager.getEntityManagerFactory(, setter: [class org.springframework.orm.jpa.JpaTransactionManager.setEntityManagerFactory(interface javax.persistence.EntityManagerFactory]
[...]
Caused by: java.lang.Exception: Unable to convert value org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean@46e9e26a to type javax.persistence.EntityManagerFactory
at org.apache.aries.blueprint.container.AggregateConverter.convert(AggregateConverter.java:172)[10:org.apache.aries.blueprint:0.3.2]
at org.apache.aries.blueprint.container.BlueprintRepository.convert(BlueprintRepository.java:373)[10:org.apache.aries.blueprint:0.3.2]
at org.apache.aries.blueprint.utils.ReflectionUtils$PropertyDescriptor.convert(ReflectionUtils.java:322)[10:org.apache.aries.blueprint:0.3.2]
at org.apache.aries.blueprint.utils.ReflectionUtils$MethodPropertyDescriptor.internalSet(ReflectionUtils.java:555)[10:org.apache.aries.blueprint:0.3.2]
at org.apache.aries.blueprint.utils.ReflectionUtils$PropertyDescriptor.set(ReflectionUtils.java:306)[10:org.apache.aries.blueprint:0.3.2]
at org.apache.aries.blueprint.container.BeanRecipe.setProperty(BeanRecipe.java:819)[10:org.apache.aries.blueprint:0.3.2]

我已经使用了我的 persistence.xml、camel-context.xml(蓝图/spring xml)并没有取得太大进展。我目前的配置是:

骆驼上下文.xml

<bean id="mysqlDataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName"        value="com.mysql.jdbc.Driver"/>
    <property name="url"                    value="jdbc:mysql://localhost/prototype"/>
    <property name="username"               value="...."/>
    <property name="password"               value="...."/>
</bean>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource"             ref="mysqlDataSource"/>
    <property name="persistenceUnitName"    value="customer1"/>
    <property name="loadTimeWeaver">
        <bean class="org.springframework.instrument.classloading.SimpleLoadTimeWeaver" />
    </property>
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter">
            <property name="databasePlatform"   value="org.apache.openjpa.jdbc.sql.MySQLDictionary" />
            <property name="showSql"            value="true"/>
        </bean>
    </property>
</bean>

<bean id="jpaTxManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory"   ref="entityManagerFactory"/>
</bean>

<bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent">
    <property name="entityManagerFactory"   ref="entityManagerFactory"/>
    <property name="transactionManager"     ref="jpaTxManager"/>
</bean>

persistence.xml

<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="customer1" transaction-type="RESOURCE_LOCAL">
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    <class>....</class>
</persistence-unit>

任何帮助将不胜感激。这几天我一直在研究这个问题。

【问题讨论】:

    标签: spring jpa apache-camel apache-servicemix


    【解决方案1】:

    由于您已经在使用 Aries JPA 和 JTA 功能的蓝图,这就是您所需要的。 为此,您还需要安装这些功能(JPA/JTA)并确保您的事务是 JTA 类型,并且使用 Aries 的实体管理器而不是 spring,您应该是安全的。 DAO 看起来更像下面这样:

    <bean id="daoBean" class="dummy.class.name.DaoBean">
       <jpa:context property="em" unitname="customer1" />
       <tx:transaction method="*" value="Required" />
    </bean>
    

    要使其正常工作,您需要引用相应的蓝图架构。

    【讨论】:

    • 这与一些其他资源一起帮助我了解了如何使用 Blueprint / Aries JPA 功能。我克服了这个错误,但现在卡在 IllegalArgumentException 上。我创建了一个单独的线程:stackoverflow.com/questions/17597941/…
    猜你喜欢
    • 2013-07-09
    • 1970-01-01
    • 2011-12-27
    • 1970-01-01
    • 1970-01-01
    • 2018-12-27
    • 1970-01-01
    • 2015-01-12
    • 2011-08-04
    相关资源
    最近更新 更多