2

JPA を使用して、Camel を使用してエンティティをデータベースに保存しようとしています。

私の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_1_0.xsd" version="1.0">

   <persistence-unit name="my-pu">
     <description>My Persistence Unit</description>
     <class>org.bencompany.camel.JabberMessage</class>
     <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
     <properties>
       <property name="openjpa.ConnectionURL"   value="mysql://localhost/jabber"/>
       <property name="openjpa.ConnectionDriverName" value="org.mysql.jdbc.Driver"/>
       <property name="javax.persistence.jdbc.user" value="root"/>
       <property name="javax.persistence.jdbc.password" value="root"/>
       <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
        <property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO"/>
     </properties>
   </persistence-unit>

</persistence>

そして私のキャメル/ビーンズ.xmlはこれです:

<?xml version="1.0"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
             http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
             http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="my-pu" />
    </bean>

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

    <bean id="myProcessor" class="org.bencompany.camel.JabberProcessor" />

    <camelContext xmlns="http://camel.apache.org/schema/blueprint"
        xmlns:order="http://fusesource.com/examples/order/v7" id="cbr-example-context">

        <route id="sendMessage">
            <from uri="file:work/cbr/input" />
            <log message="Sending Message: ${body}" />
            <to uri="xmpp://benco@xxx.com/?room=benco@conference.xxx.com&amp;password=xx&amp;nickname=bencamelbot" />
        </route>

        <route id="recieveMessage">
            <from uri="xmpp://benco@xxx.com/?room=benco@conference.xxx.com&amp;password=xx&amp;nickname=bencamelbot" />
            <to uri="myProcessor" />
            <to uri="jpa://" />
        </route>

    </camelContext>
</blueprint>

これをJBoss Fuseにデプロイしようとしているので、ブループリントを使用しています。私は次のリンクを参照として使用しており、ティーまでたどりました: https://access.redhat.com/documentation/en-US/Red_Hat_JBoss_Fuse/6.0/html/EIP_Component_Reference/files/_IDU_JPA.html

しかし、アプリケーションをデプロイしようとすると、このエラーが発生します。

org.osgi.service.blueprint.container.ComponentDefinitionException: Error setting property: PropertyDescriptor <name: entityManagerFactory, getter: class org.apache.camel.component.jpa.JpaComponent.getEntityManagerFactory(), setter: [class org.apache.camel.component.jpa.JpaComponent.setEntityManagerF
actory(interface javax.persistence.EntityManagerFactory)]
Caused by: java.lang.Exception: Unable to convert value org.springframework.orm.jpa.LocalEntityManagerFactoryBean@3ce0f4c8 to type javax.persistence.EntityManagerFactory

LocalEntityManagerFactoryBean は EntityManagerFactory を作成することになっており、JBoss / Camel のドキュメントに記載されていることを正確に行っていますが、このエラーが発生しています。

何か案は?

4

2 に答える 2

0

キャメルJPAのドキュメントによると:

Camel 2.3 では、JpaComponent はレジストリから EntityManagerFactory を自動検索します。つまり、JpaComponent でこれを構成する必要はありません。

<bean id="jpa"...だから、タグは必要ありません。

また、<to uri="jpa://" />エンドポイントとして使用しました。camel JPA documentationによると、完全修飾クラス名はオプションです。ただし、指定することをお勧めします。

于 2016-05-10T14:03:27.730 に答える
0

私は Apache Camel + Blueprint に詳しくありません。Springs LocalEntityManagerFactoryBean は、それ自体では javax.persistence.EntityManager を実装しませんが、それを取得するためのメソッドを提供します。 http://grepcode.com/file/repo1.maven.org/maven2/org.springframework/spring-orm/4.1.1.RELEASE/org/springframework/orm/jpa/LocalEntityManagerFactoryBean.java#LocalEntityManagerFactoryBean

私の調査により、重複する可能性のあるこのstackoverflowの質問が見つかりました:ServiceMix / JPA Integration - LocalContainerEntityManagerFactoryBean to type EntityManagerFactory

あなたのために仕事をするOSGiコンテナの中にメカニズム(JPAとJTA機能)があるはずです。

于 2015-01-20T09:37:09.863 に答える