JPA Component
The jpa: component allows enables you to work with databases using JPA (EJB 3 Persistence) such as for working with 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 to work with relational databases, and so on.
Sending to the endpoint
Sending POJOs to the JPA endpoint inserts entities into the databaseYou 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 (i.e. that is, a POJO with an @Entity annotation on it).
If the body does not contain an entity bean then use , put a Message Translator in front of the endpoint to perform the necessary conversion first.
Consuming from the endpoint
Consuming messages from a JPA consumer endpoint removes (or updates) entities 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.
...
Code Block |
---|
jpa:[entityClassName][?options] |
For sending to the endpoint, the entityClassName is optional. If specified, it is used to help use 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
Name | Default Value | Description |
---|---|---|
| entityClassName | Is Overrides the provided entityClassName from the URI. |
| | the The JPA persistence unit used by default. |
| | Option for JpaConsumer only. Enables / disables whether or not JPA consumer only: If |
| | Option for JpaConsumer only. Enables / disables JPA consumer only: Specifies whether or not to use exclusive locking of set an exclusive lock on each entity bean while processing the results from the poolingpolling. |
| | Option for JpaProducer only. JPA producer only: Flushes the EntityManager after the entity beans bean has been persisted. |
| | Option for JpaConsumer only. JPA consumer only: Set the maximum number of results to retrieve on the Query. |
| | Camel 1.6.1/2.0: Sets Specifies the transaction manager to use. If none provided, Camel will default use a |
| | Option for JpaConsumer only. JPA consumer only: Delay in millis milliseconds between each poll. |
| | Option for JpaConsumer only. Millis JPA consumer only: Milliseconds before polling starts. |
| | Option for JpaConsumer only. JPA consumer only: Set to |
| | Camel 2.0: Option for JpaConsumer only. JPA consumer only: An integer value to define a the maximum number of messages to gather per poll. By default, no maximum is set. Can be used to set a limit of e.g. 1000 to avoid avoid polling many thousands of messages when starting up the server that there are thousands of files. Set a value of 0 or negative to disabled itdisable. |
Message Headers
Camel will add adds the following message headers to the Exchangeexchange:
Header | Type | Description |
---|---|---|
| | Camel 2.0: The |
Configuring EntityManagerFactory
You can configure the EntityManagerFactory JPA component to use on the JpaComponent itself. For instance in Spring XMLa specific EntityManagerFactory
instance. For example, you can instantiate a JPA component that references the myEMFactory
entity manager factory, as follows:
Code Block | ||||
---|---|---|---|---|
| ||||
<bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent"> <property name="entityManagerFactory" ref="myEMFactory"/> </bean> |
Configuring TransactionManager
You can configure specify the TransactionManager
to use on the JpaComponent itself. For instance in Spring XML instance used by the JPA component. For example, you can instantiate a JPA component that references the myTransactionManager
transaction manager, as follows:
Code Block | ||||
---|---|---|---|---|
| ||||
<bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent"> <property name="entityManagerFactory" ref="myEMFactory"/> <property name="transactionManager" ref="myTransactionManager"/> </bean> |
...