[
https://issues.apache.org/jira/browse/CAMEL-27938?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Claus Ibsen updated CAMEL-27938:
--------------------------------
Description:
Found while improving the option descriptions of camel-jpa for CAMEL-23832
(commit
https://github.com/apache/camel/commit/d5a852f1554249665c55be65e7b60727f2348b3f,
pull request https://github.com/apache/camel/pull/31191).
These are separate problems of the component; the descriptions change only
documents the current behavior.
h4. 1. An unknown entityType class name is ignored
{{JpaComponent.createEndpoint}} resolves the entity class with
ClassResolver.resolveClass, which returns null for an unknown name, so a typo
leaves entityType null without an error: the producer stores the body
unconverted, findEntity calls em.find(null, key), and the consumer later fails
with "No queryType property configured".
Proposed change: use resolveMandatoryClass (after the alias lookup) so the
endpoint fails at creation.
h4. 2. pollEnrich / receive() leaks an EntityManager
{{JpaPollingConsumer.doReceive}} calls getTargetEntityManager(null, ...); the
EntityManager it creates is not stored on an exchange and no
JpaCloseEntityManagerOnCompletion is registered, so it is only closed on a
PersistenceException. For the same reason usePassedInEntityManager has no
effect for the polling consumer.
Proposed change: register JpaCloseEntityManagerOnCompletion on the returned
exchange, or close the EntityManager after the transaction when it is not
shared.
h4. 3. Smaller issues
{{JpaHelper.getTargetEntityManager}}: "allowRecreate && em == null ||
!em.isOpen()" lacks parentheses, so allowRecreate is never honoured (all
callers pass true today). entityType is required in the metadata, but the
producer works without it. persistenceUnit is required although it defaults to
"camel" and is only used without an EntityManagerFactory. The headers
CamelJpaMaximumResults and CamelJpaFirstResult have no javaType
(java.lang.Integer). The doc page says Camel logs a WARN for several
EntityManagerFactory beans; the WARN in doInit is about none being configured.
_Claude Code on behalf of davsclaus_
was:
Found while improving the option descriptions of camel-jpa for CAMEL-23832
(pull request https://github.com/apache/camel/pull/31191).
These are separate problems of the component; the descriptions change only
documents the current behavior.
h4. 1. An unknown entityType class name is ignored
{{JpaComponent.createEndpoint}} resolves the entity class with
ClassResolver.resolveClass, which returns null for an unknown name, so a typo
leaves entityType null without an error: the producer stores the body
unconverted, findEntity calls em.find(null, key), and the consumer later fails
with "No queryType property configured".
Proposed change: use resolveMandatoryClass (after the alias lookup) so the
endpoint fails at creation.
h4. 2. pollEnrich / receive() leaks an EntityManager
{{JpaPollingConsumer.doReceive}} calls getTargetEntityManager(null, ...); the
EntityManager it creates is not stored on an exchange and no
JpaCloseEntityManagerOnCompletion is registered, so it is only closed on a
PersistenceException. For the same reason usePassedInEntityManager has no
effect for the polling consumer.
Proposed change: register JpaCloseEntityManagerOnCompletion on the returned
exchange, or close the EntityManager after the transaction when it is not
shared.
h4. 3. Smaller issues
{{JpaHelper.getTargetEntityManager}}: "allowRecreate && em == null ||
!em.isOpen()" lacks parentheses, so allowRecreate is never honoured (all
callers pass true today). entityType is required in the metadata, but the
producer works without it. persistenceUnit is required although it defaults to
"camel" and is only used without an EntityManagerFactory. The headers
CamelJpaMaximumResults and CamelJpaFirstResult have no javaType
(java.lang.Integer). The doc page says Camel logs a WARN for several
EntityManagerFactory beans; the WARN in doInit is about none being configured.
_Claude Code on behalf of davsclaus_
> camel-jpa: an unknown entityType is ignored, pollEnrich leaks an EntityManager
> ------------------------------------------------------------------------------
>
> Key: CAMEL-27938
> URL: https://issues.apache.org/jira/browse/CAMEL-27938
> Project: Camel
> Issue Type: Bug
> Components: camel-jpa
> Reporter: Claus Ibsen
> Priority: Minor
> Fix For: 4.25.0
>
>
> Found while improving the option descriptions of camel-jpa for CAMEL-23832
> (commit
> https://github.com/apache/camel/commit/d5a852f1554249665c55be65e7b60727f2348b3f,
> pull request https://github.com/apache/camel/pull/31191).
> These are separate problems of the component; the descriptions change only
> documents the current behavior.
> h4. 1. An unknown entityType class name is ignored
> {{JpaComponent.createEndpoint}} resolves the entity class with
> ClassResolver.resolveClass, which returns null for an unknown name, so a typo
> leaves entityType null without an error: the producer stores the body
> unconverted, findEntity calls em.find(null, key), and the consumer later
> fails with "No queryType property configured".
> Proposed change: use resolveMandatoryClass (after the alias lookup) so the
> endpoint fails at creation.
> h4. 2. pollEnrich / receive() leaks an EntityManager
> {{JpaPollingConsumer.doReceive}} calls getTargetEntityManager(null, ...); the
> EntityManager it creates is not stored on an exchange and no
> JpaCloseEntityManagerOnCompletion is registered, so it is only closed on a
> PersistenceException. For the same reason usePassedInEntityManager has no
> effect for the polling consumer.
> Proposed change: register JpaCloseEntityManagerOnCompletion on the returned
> exchange, or close the EntityManager after the transaction when it is not
> shared.
> h4. 3. Smaller issues
> {{JpaHelper.getTargetEntityManager}}: "allowRecreate && em == null ||
> !em.isOpen()" lacks parentheses, so allowRecreate is never honoured (all
> callers pass true today). entityType is required in the metadata, but the
> producer works without it. persistenceUnit is required although it defaults
> to "camel" and is only used without an EntityManagerFactory. The headers
> CamelJpaMaximumResults and CamelJpaFirstResult have no javaType
> (java.lang.Integer). The doc page says Camel logs a WARN for several
> EntityManagerFactory beans; the WARN in doInit is about none being configured.
> _Claude Code on behalf of davsclaus_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)