<commit_before>[[jpa-component]]
= JPA Component

*Available as of Camel version 1.0*

The 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:

[source,xml]
------------------------------------------------------------
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-jpa</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>
------------------------------------------------------------

== Sending to the endpoint

You 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
http://java.sun.com/javaee/5/docs/api/javax/persistence/Entity.html[@Entity]
annotation on it) or a collection or array of entity beans.

If the body is a List of entities, make sure to use
*entityType=java.util.ArrayList* as a configuration passed to the
producer endpoint.

If the body does not contain one of the previous listed types, put a
Message Translator in front of the
endpoint to perform the necessary conversion first.

You can use `query`, `namedQuery` or `nativeQuery`
for the producer as well. Also in the value of the `parameters`, you can use
Simple expression which allows you to retrieve parameter values from Message body, header
and etc. Those query can be used for retrieving a set of data with using `SELECT`
JPQL/SQL statement as well as executing bulk update/delete with using `UPDATE`/`DELETE`
JPQL/SQL statement. Please note that you need to specify `useExecuteUpdate` to `true`
if you execute `UPDATE`/`DELETE` with `namedQuery` as camel don't look into the
named query unlike `query` and `nativeQuery`.


== Consuming from the endpoint

Consuming 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
(and when routing is done), 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
http://camel.apache.org/maven/current/camel-jpa/apidocs/org/apache/camel/component/jpa/Consumed.html[@Consumed]
which will be invoked on your entity bean when the entity bean when it
has been processed (and when routing is done).

You can use http://camel.apache.org/maven/current/camel-jpa/apidocs/org/apache/camel/component/jpa/PreConsumed.html[@PreConsumed]
which will be invoked on your entity bean before it has been processed
(before routing).

If you are consuming a lot (100K+) of rows and experience OutOfMemory
problems you should set the maximumResults to sensible value.

== URI format

[source,java]
-----------------------------
jpa:entityClassName[?options]
-----------------------------

For sending to the endpoint, the _entityClassName_ is optional. If
specified, it helps the http://camel.apache.org/type-converter.html[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




// component options: START
The JPA component supports 6 options, which are listed below.



[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *entityManagerFactory* (common) | To use the EntityManagerFactory. This is strongly recommended to configure. |  | EntityManagerFactory
| *transactionManager* (common) | To use the PlatformTransactionManager for managing transactions. |  | PlatformTransaction Manager
| *joinTransaction* (common) | The camel-jpa component will join transaction by default. You can use this option to turn this off, for example if you use LOCAL_RESOURCE and join transaction doesn't work with your JPA provider. This option can also be set globally on the JpaComponent, instead of having to set it on all endpoints. | true | boolean
| *sharedEntityManager* (common) | Whether to use Spring's SharedEntityManager for the consumer/producer. Note in most cases joinTransaction should be set to false as this is not an EXTENDED EntityManager. | false | boolean
| *resolveProperty Placeholders* (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean
| *basicPropertyBinding* (advanced) | Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities | false | boolean
|===
// component options: END








// endpoint options: START
The JPA endpoint is configured using URI syntax:

----
jpa:entityType
----

with the following path and query parameters:

=== Path Parameters (1 parameters):


[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *entityType* | *Required* The JPA annotated class to use as entity. |  | Class
|===


=== Query Parameters (45 parameters):


[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *joinTransaction* (common) | The camel-jpa component will join transaction by default. You can use this option to turn this off, for example if you use LOCAL_RESOURCE and join transaction doesn't work with your JPA provider. This option can also be set globally on the JpaComponent, instead of having to set it on all endpoints. | true | boolean
| *maximumResults* (common) | Set the maximum number of results to retrieve on the Query. | -1 | int
| *namedQuery* (common) | To use a named query. |  | String
| *nativeQuery* (common) | To use a custom native query. You may want to use the option resultClass also when using native queries. |  | String
| *persistenceUnit* (common) | *Required* The JPA persistence unit used by default. | camel | String
| *query* (common) | To use a custom query. |  | String
| *resultClass* (common) | Defines the type of the returned payload (we will call entityManager.createNativeQuery(nativeQuery, resultClass) instead of entityManager.createNativeQuery(nativeQuery)). Without this option, we will return an object array. Only has an affect when using in conjunction with native query when consuming data. |  | Class
| *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean
| *consumeDelete* (consumer) | If true, the entity is deleted after it is consumed; if false, the entity is not deleted. | true | boolean
| *consumeLockEntity* (consumer) | Specifies whether or not to set an exclusive lock on each entity bean while processing the results from polling. | true | boolean
| *deleteHandler* (consumer) | To use a custom DeleteHandler to delete the row after the consumer is done processing the exchange |  | DeleteHandler
| *lockModeType* (consumer) | To configure the lock mode on the consumer. | PESSIMISTIC_WRITE | LockModeType
| *maxMessagesPerPoll* (consumer) | An integer value to define the maximum number of messages to gather per poll. By default, no maximum is set. Can be used to avoid polling many thousands of messages when starting up the server. Set a value of 0 or negative to disable. |  | int
| *preDeleteHandler* (consumer) | To use a custom Pre-DeleteHandler to delete the row after the consumer has read the entity. |  | DeleteHandler
| *sendEmptyMessageWhenIdle* (consumer) | If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead. | false | boolean
| *skipLockedEntity* (consumer) | To configure whether to use NOWAIT on lock and silently skip the entity. | false | boolean
| *transacted* (consumer) | Whether to run the consumer in transacted mode, by which all messages will either commit or rollback, when the entire batch has been processed. The default behavior (false) is to commit all the previously successfully processed messages, and only rollback the last failed message. | false | boolean
| *exceptionHandler* (consumer) | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. |  | ExceptionHandler
| *exchangePattern* (consumer) | Sets the exchange pattern when the consumer creates an exchange. |  | ExchangePattern
| *parameters* (consumer) | This key/value mapping is used for building the query parameters. It is expected to be of the generic type java.util.Map where the keys are the named parameters of a given JPA query and the values are their corresponding effective values you want to select for. When it's used for producer, Simple expression can be used as a parameter value. It allows you to retrieve parameter values from the message body, header and etc. |  | Map
| *pollStrategy* (consumer) | A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation before an Exchange have been created and being routed in Camel. |  | PollingConsumerPoll Strategy
| *findEntity* (producer) | If enabled then the producer will find a single entity by using the message body as key and resultClass as the class type. This can be used instead of using query to find a single entity. | false | boolean
| *flushOnSend* (producer) | Flushes the EntityManager after the entity bean has been persisted. | true | boolean
| *lazyStartProducer* (producer) | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean
| *remove* (producer) | Indicates to use entityManager.remove(entity). | false | boolean
| *useExecuteUpdate* (producer) | To configure whether to use executeUpdate() when producer executes a query. When you use INSERT, UPDATE or DELETE statement as a named query, you need to specify this option to 'true'. |  | Boolean
| *usePersist* (producer) | Indicates to use entityManager.persist(entity) instead of entityManager.merge(entity). Note: entityManager.persist(entity) doesn't work for detached entities (where the EntityManager has to execute an UPDATE instead of an INSERT query)! | false | boolean<commit_msg>Regen<commit_after>[[jpa-component]]
= JPA Component

*Available as of Camel version 1.0*

The 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:

[source,xml]
------------------------------------------------------------
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-jpa</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>
------------------------------------------------------------

== Sending to the endpoint

You 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
http://java.sun.com/javaee/5/docs/api/javax/persistence/Entity.html[@Entity]
annotation on it) or a collection or array of entity beans.

If the body is a List of entities, make sure to use
*entityType=java.util.ArrayList* as a configuration passed to the
producer endpoint.

If the body does not contain one of the previous listed types, put a
Message Translator in front of the
endpoint to perform the necessary conversion first.

You can use `query`, `namedQuery` or `nativeQuery`
for the producer as well. Also in the value of the `parameters`, you can use
Simple expression which allows you to retrieve parameter values from Message body, header
and etc. Those query can be used for retrieving a set of data with using `SELECT`
JPQL/SQL statement as well as executing bulk update/delete with using `UPDATE`/`DELETE`
JPQL/SQL statement. Please note that you need to specify `useExecuteUpdate` to `true`
if you execute `UPDATE`/`DELETE` with `namedQuery` as camel don't look into the
named query unlike `query` and `nativeQuery`.


== Consuming from the endpoint

Consuming 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
(and when routing is done), 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
http://camel.apache.org/maven/current/camel-jpa/apidocs/org/apache/camel/component/jpa/Consumed.html[@Consumed]
which will be invoked on your entity bean when the entity bean when it
has been processed (and when routing is done).

You can use http://camel.apache.org/maven/current/camel-jpa/apidocs/org/apache/camel/component/jpa/PreConsumed.html[@PreConsumed]
which will be invoked on your entity bean before it has been processed
(before routing).

If you are consuming a lot (100K+) of rows and experience OutOfMemory
problems you should set the maximumResults to sensible value.

== URI format

[source,java]
-----------------------------
jpa:entityClassName[?options]
-----------------------------

For sending to the endpoint, the _entityClassName_ is optional. If
specified, it helps the http://camel.apache.org/type-converter.html[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




// component options: START
The JPA component supports 6 options, which are listed below.



[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *entityManagerFactory* (common) | To use the EntityManagerFactory. This is strongly recommended to configure. |  | EntityManagerFactory
| *transactionManager* (common) | To use the PlatformTransactionManager for managing transactions. |  | PlatformTransaction Manager
| *joinTransaction* (common) | The camel-jpa component will join transaction by default. You can use this option to turn this off, for example if you use LOCAL_RESOURCE and join transaction doesn't work with your JPA provider. This option can also be set globally on the JpaComponent, instead of having to set it on all endpoints. | true | boolean
| *sharedEntityManager* (common) | Whether to use Spring's SharedEntityManager for the consumer/producer. Note in most cases joinTransaction should be set to false as this is not an EXTENDED EntityManager. | false | boolean
| *resolveProperty Placeholders* (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean
| *basicPropertyBinding* (advanced) | Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities | false | boolean
|===
// component options: END








// endpoint options: START
The JPA endpoint is configured using URI syntax:

----
jpa:entityType
----

with the following path and query parameters:

=== Path Parameters (1 parameters):


[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *entityType* | *Required* The JPA annotated class to use as entity. |  | Class
|===


=== Query Parameters (45 parameters):


[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *joinTransaction* (common) | The camel-jpa component will join transaction by default. You can use this option to turn this off, for example if you use LOCAL_RESOURCE and join transaction doesn't work with your JPA provider. This option can also be set globally on the JpaComponent, instead of having to set it on all endpoints. | true | boolean
| *maximumResults* (common) | Set the maximum number of results to retrieve on the Query. | -1 | int
| *namedQuery* (common) | To use a named query. |  | String
| *nativeQuery* (common) | To use a custom native query. You may want to use the option resultClass also when using native queries. |  | String
| *persistenceUnit* (common) | *Required* The JPA persistence unit used by default. | camel | String
| *query* (common) | To use a custom query. |  | String
| *resultClass* (common) | Defines the type of the returned payload (we will call entityManager.createNativeQuery(nativeQuery, resultClass) instead of entityManager.createNativeQuery(nativeQuery)). Without this option, we will return an object array. Only has an affect when using in conjunction with native query when consuming data. |  | Class
| *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean
| *consumeDelete* (consumer) | If true, the entity is deleted after it is consumed; if false, the entity is not deleted. | true | boolean
| *consumeLockEntity* (consumer) | Specifies whether or not to set an exclusive lock on each entity bean while processing the results from polling. | true | boolean
| *deleteHandler* (consumer) | To use a custom DeleteHandler to delete the row after the consumer is done processing the exchange |  | DeleteHandler
| *lockModeType* (consumer) | To configure the lock mode on the consumer. | PESSIMISTIC_WRITE | LockModeType
| *maxMessagesPerPoll* (consumer) | An integer value to define the maximum number of messages to gather per poll. By default, no maximum is set. Can be used to avoid polling many thousands of messages when starting up the server. Set a value of 0 or negative to disable. |  | int
| *preDeleteHandler* (consumer) | To use a custom Pre-DeleteHandler to delete the row after the consumer has read the entity. |  | DeleteHandler
| *sendEmptyMessageWhenIdle* (consumer) | If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead. | false | boolean
| *skipLockedEntity* (consumer) | To configure whether to use NOWAIT on lock and silently skip the entity. | false | boolean
| *transacted* (consumer) | Whether to run the consumer in transacted mode, by which all messages will either commit or rollback, when the entire batch has been processed. The default behavior (false) is to commit all the previously successfully processed messages, and only rollback the last failed message. | false | boolean
| *exceptionHandler* (consumer) | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. |  | ExceptionHandler
| *exchangePattern* (consumer) | Sets the exchange pattern when the consumer creates an exchange. |  | ExchangePattern
| *parameters* (consumer) | This key/value mapping is used for building the query parameters. It is expected to be of the generic type java.util.Map where the keys are the named parameters of a given JPA query and the values are their corresponding effective values you want to select for. When it's used for producer, Simple expression can be used as a parameter value. It allows you to retrieve parameter values from the message body, header and etc. |  | Map
| *pollStrategy* (consumer) | A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation before an Exchange have been created and being routed in Camel. |  | PollingConsumerPoll Strategy
| *findEntity* (producer) | If enabled then the producer will find a single entity by using the message body as key and entityType as the class type. This can be used instead of a query to find a single entity. | false | boolean
| *flushOnSend* (producer) | Flushes the EntityManager after the entity bean has been persisted. | true | boolean
| *lazyStartProducer* (producer) | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean
| *remove* (producer) | Indicates to use entityManager.remove(entity). | false | boolean
| *useExecuteUpdate* (producer) | To configure whether to use executeUpdate() when producer executes a query. When you use INSERT, UPDATE or DELETE statement as a named query, you need to specify this option to 'true'. |  | Boolean
| *usePersist* (producer) | Indicates to use entityManager.persist(entity) instead of entityManager.merge(entity). Note: entityManager.persist(entity) doesn't work for detached entities (where the EntityManager has to execute an UPDATE instead of an INSERT query)! | false | boolean
{'fraction_non_alphanumeric': 0.08116758417616182, 'fraction_numerical': 0.00298724021678829, 'mean_word_length': 4.327119799954535, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4818906', 'n_tokens_mistral': 5950, 'n_tokens_neox': 5681, 'n_words': 3163}