[ 
https://issues.apache.org/jira/browse/CAMEL-21873?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18123068#comment-18123068
 ] 

Claus Ibsen commented on CAMEL-21873:
-------------------------------------

Some thoughts on the direction for this component, following the review of 
https://github.com/apache/camel/pull/27314

camel-jpa with Hibernate as the JPA provider already covers plain 
persist/merge/query/poll. A camel-hibernate component should therefore be small 
and focused on what camel-jpa can't do, rather than copy camel-jpa. (Camel is 
on Hibernate 7.4; the APIs below should be verified against that version.)

h3. 1. Easier setup (no persistence.xml or Spring)
* The component bootstraps the SessionFactory itself from a few options: a 
{{dataSource}} (a bean reference, or the one provided by Spring Boot/Quarkus), 
{{packagesToScan}} or a list of entity classes, a {{schemaAction}} 
(none/validate/update/create), and a pass-through map for any {{hibernate.*}} 
setting. The dialect is auto-detected.
* The component owns the SessionFactory lifecycle: it creates it on start and 
closes it on stop.
* Transactions use Hibernate's own Session transactions, with no spring-orm / 
PlatformTransactionManager needed. It still joins an existing transaction when 
the route is transacted.
* If an existing SessionFactory/EntityManagerFactory is in the registry (Spring 
Boot, Quarkus), use it instead of building one.
* Good for Camel CLI and YAML users: entity classes plus datasource properties 
are enough to run.

h3. 2. Hibernate-only features
# *Competing consumers with SKIP_LOCKED*: the polling consumer locks the rows 
it takes and skips rows already locked by another node, portably across 
databases. That makes "poll a table as a queue" safe in a cluster.
# *StatelessSession bulk insert/upsert*: batched writes with no persistence 
context, for batch/ETL routes (aggregate N rows, write them in one go).
# *Streaming large results*: ScrollableResults or a result stream with a fetch 
size, so each row flows through the route as it's read and large tables don't 
need to fit in memory.
# *Separate query and update APIs* (SelectionQuery / MutationQuery): the 
endpoint knows whether its query reads or writes when it starts, instead of 
guessing from the first word of the query text. Hibernate can also check the 
HQL at startup, so a broken query fails fast.
# *Read-only sessions/queries for consumers*: no change tracking for rows that 
are only read.
# *Natural-id lookup*: find an entity by a business key (order number, email) 
instead of its primary key.
# *Filters*: {{@Filter}} definitions turned on per endpoint, with their 
parameters set in the route.
# *Multi-tenancy*: the tenant identifier comes from route configuration or an 
expression the route author controls, never directly from an untrusted message 
header.
# Later, maybe: *dynamic-map entities*, which persist and query Map bodies with 
no Java entity classes. That would suit low-code and YAML users.

h3. 3. Not in the component
* No header that replaces the configured query (e.g. {{CamelHibernateQuery}}). 
Queries come from the route author only, and message data goes in as bound 
parameters, as in camel-jpa. Otherwise header injection turns into HQL 
injection (see the security model).

h3. Suggested first version
The easier setup plus items 1-4. If there is agreement that SKIP_LOCKED and 
streaming should also work through JPA lock hints, those two could go into 
camel-jpa instead, leaving the easier setup and StatelessSession as the reason 
for the separate component.

_Claude Code on behalf of davsclaus_


> camel-hibernate component
> -------------------------
>
>                 Key: CAMEL-21873
>                 URL: https://issues.apache.org/jira/browse/CAMEL-21873
>             Project: Camel
>          Issue Type: New Feature
>            Reporter: Claus Ibsen
>            Assignee: Ramu
>            Priority: Major
>             Fix For: 4.x
>
>
> Hibernate 7.x is going to be ASL2 licensed so we can have a first class 
> component at Camel. It can use JPA/Hibernate APIs. But extending camel-jpa 
> and using some of the extra powers of hibernate we can make this a bit easier 
> for users than before with JPA and setting it up for Hibernate
> [https://in.relation.to/2025/03/14/orm-asl/]
>  
> There was also the old camel-hibernate code at camel-extra we can take a look 
> at



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to