JPAPage edited by Claus IbsenJPA ComponentThe jpa component enables you to store and retrieve Java objects from persistent storage using EJB 3's Java Persistence Architecture (JPA), which is a standard interface layer that wraps Object/Relational Mapping (ORM) products such as OpenJPA, Hibernate, TopLink, and so on. Maven users will need to add the following dependency to their pom.xml for this component: Sending to the endpointYou can store a Java entity bean in a database by sending it to a JPA producer endpoint. The body of the In message is assumed to be an entity bean (that is, a POJO with an @Entity annotation on it). If the body does not contain an entity bean, put a Message Translator in front of the endpoint to perform the necessary conversion first. Consuming from the endpointConsuming messages from a JPA consumer endpoint removes (or updates) entity beans in the database. This allows you to use a database table as a logical queue: consumers take messages from the queue and then delete/update them to logically remove them from the queue. If you do not wish to delete the entity bean when it has been processed, you can specify consumeDelete=false on the URI. This will result in the entity being processed each poll. If you would rather perform some update on the entity to mark it as processed (such as to exclude it from a future query) then you can annotate a method with @Consumed which will be invoked on your entity bean when the entity bean is consumed. URI formatFor sending to the endpoint, the entityClassName is optional. If specified, it helps the Type Converter to ensure the body is of the correct type. For consuming, the entityClassName is mandatory. You can append query options to the URI in the following format, ?option=value&option=value&... Options
Message HeadersCamel adds the following message headers to the exchange:
Configuring EntityManagerFactoryIts strongly advised to configure the JPA component to use a specific EntityManagerFactory instance. If failed to do so each JpaEndpoint will auto create their own instance of EntityManagerFactory which most often is not what you want. For example, you can instantiate a JPA component that references the myEMFactory entity manager factory, as follows: 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 as shown above. You only need to do so if there is ambiguity, in which case Camel will log a WARN. Configuring TransactionManagerIts strongly advised to configure the TransactionManager instance used by the JPA component. If failed to do so each JpaEndpoint will auto create their own instance of TransactionManager which most often is not what you want. For example, you can instantiate a JPA component that references the myTransactionManager transaction manager, as follows: In Camel 2.3 the JpaComponent will auto lookup the TransactionManager from the Registry which means you do not need to configure this on the JpaComponent as shown above. You only need to do so if there is ambiguity, in which case Camel will log a WARN. ExampleSee Tracer Example for an example using JPA to store traced messages into a database. See Also
Change Notification Preferences
View Online
|
View Change
|
Add Comment
|
- [CONF] Apache Camel > JPA confluence
- [CONF] Apache Camel > JPA confluence
- [CONF] Apache Camel > JPA confluence
- [CONF] Apache Camel > JPA confluence
- [CONF] Apache Camel > JPA confluence
- [CONF] Apache Camel > JPA confluence
- [CONF] Apache Camel > JPA confluence
- [CONF] Apache Camel > JPA confluence