ammachado opened a new pull request, #31303:
URL: https://github.com/apache/camel/pull/31303

   # Description
   
   Fixes [CAMEL-27938](https://issues.apache.org/jira/browse/CAMEL-27938), 
found while improving the camel-jpa option descriptions for CAMEL-23832 
(#31191).
   
   **1. An unknown `entityType` was ignored.** `JpaComponent.createEndpoint` 
used `ClassResolver.resolveClass`, which returns `null` for a class it cannot 
load, so a typo left `entityType` null: the producer stored the body 
unconverted, `findEntity` called `em.find(null, key)`, and the consumer failed 
later with `No queryType property configured`. It now uses 
`resolveMandatoryClass` after the alias lookup, so creating the endpoint fails 
with a `ResolveEndpointFailedException` caused by a `ClassNotFoundException`.
   
   This exposed a bug in `JpaTest`: it built the List endpoint as 
`jpa://...SendEmail&entityType=java.util.List` (no `?`), so the query parameter 
became part of the class name and was silently ignored. The test now picks `?` 
or `&` from the base URI.
   
   **2. `pollEnrich` / `receive()` leaked an EntityManager.** 
`JpaPollingConsumer.doReceive` called `getTargetEntityManager(null, ...)`, so 
the EntityManager was never registered for closing (only closed on a 
`PersistenceException`). It now creates the exchange first and passes it, so 
`JpaHelper` registers `JpaCloseEntityManagerOnCompletion`, the same path the 
producer uses. `PollEnricher` hands the completion over to the enriched 
exchange; a `ConsumerTemplate` closes it on `doneUoW`. The `CamelEntityManager` 
header stays usable while the exchange is routed (the entities are already 
detached by the existing `flush()` + `clear()`).
   
   **3. Smaller issues**
   - `JpaHelper.getTargetEntityManager`: added the missing parentheses so 
`allowRecreate` is honoured (all callers pass `true` today, so no behavior 
change).
   - `entityType` and `persistenceUnit` are no longer marked required (the 
producer works without an entity class; `persistenceUnit` defaults to `camel`).
   - `CamelJpaMaximumResults` and `CamelJpaFirstResult` now declare 
`java.lang.Integer`.
   - Doc page: the WARN is logged when no EntityManagerFactory is configured, 
not when there are several.
   
   Upgrade guide entry added to `camel-4x-upgrade-guide-4_25.adoc`.
   
   **Tests:** `JpaComponentTest#testUnknownEntityTypeFailsEndpointCreation`, 
`JpaPollingConsumerCloseEntityManagerTest` (pollEnrich and 
ConsumerTemplate/`doneUoW`), `JpaHelperTest` (`allowRecreate`). All five fail 
on the previous code and pass with the fix. `mvn clean install -pl 
components/camel-jpa`: 173 tests (1 skipped by its own condition, 
`JpaRouteSkipLockedEntityTest`) and 5 ITs pass.
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
   
     Not from the root folder: built `components/camel-jpa`, then ran 
`etc/scripts/regen.sh` (`mvn -Pregen` + camel-catalog install); the working 
tree stayed clean afterwards.
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code) on behalf of 
Adriano Machado (@ammachado)
   
   _This was generated by an AI agent and may contain inaccuracies. Please 
verify before relying on it._


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to