Skip to content
This repository has been archived by the owner on Apr 28, 2022. It is now read-only.

fharms/camel-jpa-entitymanager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Camel Entity Manager Bean Processor

Camel comes with a JPA module for using JPA within a route, by simply using the URI format "jpa:entityClassName[?options]". This make it real easy to make CRUD operation with Camel. But accessing Camels entity manager and join it with with current route transaction is a little more tricky, and require some manual work.

The Camel Entity Manager is a post processor that serves the purpose, to inject a proxy around the EntityManager and handle the logic around the injected entity manager. It support both use cases where the Camel has created the EntityManager as part of the JPA consumer or producer, or for none JPA consumers or producers.

Requirements for running using Camel Entity Manager Bean Processor

  • Maven 3.x or higher

  • JDK 8 or higher

    Disclaimer : Only tested with Spring and Hibernate 5.0.1

User guide

For using the Camel Entity Manager post processor add this dependency to your project

 <dependency>
      <artifactId>camel.jpa.entitymanager</artifactId>
      <groupId>com.github.fharms</groupId>
      <version>0.0.2</version>
 </dependency>

Annotate the field with @PersistenceContext and type EntityManager as you normal with do.

  @javax.persistence.PersistenceContext(unitName = "emf")
  EntityManager em;

Working with multiple JPA components in camel

  @javax.persistence.PersistenceContext(unitName = "emf")
  EntityManager em1;
  
  @javax.persistence.PersistenceContext(unitName = "emf2")
  EntityManager em2;

Force the Camel entity manager bean processor to ignore any Entity Manager created by the JPA consumer

  
  @IgnoreCamelEntityManager
  @javax.persistence.PersistenceContext(unitName = "emf")
  EntityManager em;
  
  
  @IgnoreCamelEntityManager
  public void findMyEntity(Exchange exchange) {
     em.find(MyEntity.class, exchange.getIn().getBody(Integer.class))
  }

Build the source

This is real easy, just execute the command :

mvn install

Build Status

Build Status