2

I'm trying to use JPA to save an Entity to a database using Camel.

I have my persistence.xml as this:

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

and my camel / beans .xml is this:

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

I'm using Blueprint as I'm trying to deploy this onto JBoss Fuse. I've been using the following link as a reference, and I have followed it to the tee: https://access.redhat.com/documentation/en-US/Red_Hat_JBoss_Fuse/6.0/html/EIP_Component_Reference/files/_IDU_JPA.html

But when I try to deploy my application, I get this error.

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

The LocalEntityManagerFactoryBean is supposed to create an EntityManagerFactory, and I'm doing exactly what the JBoss / Camel documentation says, but this error is coming up.

Any ideas?

Ben Harris
  • 1,734
  • 3
  • 15
  • 24

2 Answers2

0

I am not familiar with Apache Camel + Blueprint. Springs LocalEntityManagerFactoryBean does not implement the javax.persistence.EntityManager by itself, but provides methods to get it. http://grepcode.com/file/repo1.maven.org/maven2/org.springframework/spring-orm/4.1.1.RELEASE/org/springframework/orm/jpa/LocalEntityManagerFactoryBean.java#LocalEntityManagerFactoryBean

Due to my research i found this stackoverflow question which could be a duplicate: ServiceMix / JPA Integration - LocalContainerEntityManagerFactoryBean to type EntityManagerFactory

It seems there should be mechanism (JPA and JTA Feature) insideyour OSGi container which should do the work for you.

Community
  • 1
  • 1
Martin Baumgartner
  • 3,524
  • 3
  • 20
  • 31
0

According to the camel JPA documentation:

In Camel 2.3 the JpaComponent will auto lookup the EntityManagerFactory from the Registry which means you do not need to configure this on the JpaComponent

So you don't need the <bean id="jpa"... tag.

Also, you've used <to uri="jpa://" /> as the endpoint. According to the camel JPA documentation, the fully-qualified class name is optional. However I have found that it is a good idea to specify it.

mdarwin
  • 1,684
  • 7
  • 28
  • 72