I solved the problem.
I use this in my RouteBuilder:
from("jpa:org.apache.camel.example.etl.Customer?consumeDelete=false&delay=3000&consumeLockEntity=false")
.process(new CustomerTransformer());
And my processor looks like this :
public void process(Exchange exchange) throws Exception {
JpaTemplate template =
exchange.getIn().getHeader("CamelJpaTemplate",
JpaTemplate.class);
List<Customer> customers = CastUtils.cast(template.find("SELECT
x FROM
Customer x"));
System.out.println(customers.size());
EntityManager em =
Persistence.createEntityManagerFactory("camel2").createEntityManager();
EntityTransaction trans = em.getTransaction();
trans.begin();
for (Customer fromCustomer : customers){
Customer2 toCustomer = new Customer2();
toCustomer.setId(fromCustomer.getId());
toCustomer.setUserName(fromCustomer.getUserName());
toCustomer.setFirstName(fromCustomer.getFirstName());
toCustomer.setCity(fromCustomer.getCity());
toCustomer.setStreet(fromCustomer.getStreet());
em.persist(toCustomer);
}
trans.commit();
em.close();
}
And it works perfectly.
Thank you for your help.
Best,
Idriss
--
View this message in context:
http://camel.465427.n5.nabble.com/CSV-to-database-tp4435750p5041482.html
Sent from the Camel - Users mailing list archive at Nabble.com.