Matthias
Matthias

Reputation: 51

Apache Camel JPA: read from multiple tables

I am new to camel-jpa and would need your help with the following problem:

I need to read data from a database table, transform it and save it into another database:

<route id="FromEmployee1ToEmployee2">
      <from uri="jpa1://Employee1?consumeDelete=false&amp;consumer.namedQuery=getAll" />
      <bean ref="transformerBean"/>
      <to uri="jpa2://Employee2"/>
</route>

This is already working great! But the problem now is that I need to look up some data for Employee1 from a different table (I need to read the "last_modified" date for that entry). In SQL I would simply do like this: select last_modified from table2 where table2.id = <employee.ID>. but how can I realise this with camel-jpa?

Upvotes: 1

Views: 2752

Answers (2)

Matthias
Matthias

Reputation: 51

here is my solution (just in case someone is struggling with the same problem):

since its not possible to dynamically pass attributes to a named query in a camel route (at least, I couldn't find any way to do it...), i used a bean to deal with it:

<route...
  <from uri="jpa1://Entity1" />
  <bean ref="MyBean" />
  <to uri="jpa2://Entity2" />    
</route>

and within the bean, i use a (autowired) DAO to call my queries. This allows me to do all the kinds of content enrichment i need ...

well, it works great so far, but i think there could me a more elegant way of doing this with camel...

BR, M

Upvotes: 0

Claus Ibsen
Claus Ibsen

Reputation: 55750

The camel-jpa component offers options to use a query, such as a named query. This allows you to write in SQL like using the JPL (I think thats the JPA name for SQL).

There is a little example at http://camel.apache.org/jpa

Upvotes: 0

Related Questions