gnodet-bot commented on code in PR #30184:
URL: https://github.com/apache/camel/pull/30184#discussion_r4583978707
##########
components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java:
##########
@@ -362,6 +364,19 @@ public boolean isSkipLockedEntity() {
return skipLockedEntity;
}
+ /**
+ * Sets how long, in millis, to wait for the lock of an entity that
another transaction holds. It is given to the
+ * JPA provider as the <tt>jakarta.persistence.lock.timeout</tt> hint. The
default <tt>0</tt> sets no timeout. Not
+ * used with skipLockedEntity.
+ */
+ public void setLockTimeout(long lockTimeout) {
+ this.lockTimeout = lockTimeout;
+ }
Review Comment:
⚠️ **Missing validation for negative `lockTimeout`:** `setLockTimeout(-1)`
falls through to the no-hint branch (`lockTimeout > 0` is false), so the lock
waits indefinitely — silently ignoring the user's intent. Camel's Duration
parser rejects negative strings like `"-1s"`, but programmatic Java DSL use
bypasses that guard.
Add a range check in the setter:
```suggestion
public void setLockTimeout(long lockTimeout) {
if (lockTimeout < 0) {
throw new IllegalArgumentException("lockTimeout must be >= 0,
was: " + lockTimeout);
}
this.lockTimeout = lockTimeout;
}
```
##########
components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java:
##########
@@ -66,11 +67,12 @@ public class JpaConsumer extends
ScheduledBatchPollingConsumer {
private Class<?> resultClass;
private boolean transacted;
private boolean skipLockedEntity;
+ private long lockTimeout;
private final AtomicBoolean notEntityWarned = new AtomicBoolean();
static {
NOWAIT = new HashMap<>();
- NOWAIT.put("jakarta.persistence.lock.timeout", 0L);
+ NOWAIT.put(LOCK_TIMEOUT, 0L);
Review Comment:
🔎 **Type inconsistency between `NOWAIT` and the new `lockTimeout` path:**
`NOWAIT` passes `0L` (`Long`) for `jakarta.persistence.lock.timeout`, while the
new code passes an `int` (`Integer`). The JPA spec says the hint value should
be `Integer`. The `Long` on NOWAIT works in practice because Hibernate reads it
via `Number.intValue()`, but the two paths are inconsistent.
Consider aligning the NOWAIT initializer:
```suggestion
NOWAIT.put(LOCK_TIMEOUT, 0);
```
--
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]