Skip to content

Conversation

mzellho
Copy link
Contributor

@mzellho mzellho commented Aug 28, 2025

Hibernate 7 introduced a new API to find multiple Entities by their IDs, which is not yet available in Hibernate ORM with Panache. To allow making use of it, this PR introduces a new API called findByIds (returns List<Entity>).

It also adds a similar findByIds API for MongoDB with Panache, albeit only performing a collection.find(Filters.in("_id", ids)), to avoid falling short.

@mzellho
Copy link
Contributor Author

mzellho commented Aug 28, 2025

@gsmet can you maybe point me to how to achieve the same for Mongo, so the API is consistently available? Or maybe point me to somebody else or some resource?

Also, this PR is still a DRAFT as I definitely should also add some tests...

@mzellho mzellho changed the title feat: allow to use Hibernate 7s findMultiple in Panache Allow to use Hibernate 7s findMultiple in Panache Aug 28, 2025
@mzellho
Copy link
Contributor Author

mzellho commented Aug 28, 2025

@geoand thank you - I found these files, unfortunately I have zero clue about Mongo, and I could not find an API to do a findMultiple over there (or at least none that was obvious enough for me to choose). I will continue to look for a way...

@geoand
Copy link
Contributor

geoand commented Aug 28, 2025

It's possible that the Mongo driver does not have such a capability, but I don't remember off hand

@mzellho mzellho force-pushed the findMultiple branch 2 times, most recently from b58f5ef to 696c7bc Compare August 28, 2025 14:16
@mzellho mzellho force-pushed the findMultiple branch 3 times, most recently from 0c6d5c7 to e5c8f46 Compare August 28, 2025 15:24
@gastaldi gastaldi requested a review from FroMage August 28, 2025 15:26
@mzellho mzellho force-pushed the findMultiple branch 6 times, most recently from c1e48d4 to efa2654 Compare August 28, 2025 17:37
@mzellho mzellho marked this pull request as ready for review August 28, 2025 17:38
@mzellho mzellho changed the title Allow to use Hibernate 7s findMultiple in Panache Add findByIds API to Panache Aug 28, 2025
Copy link
Member

@FroMage FroMage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea, thanks for the PR :)

@quarkus-bot quarkus-bot bot added the area/spring Issues relating to the Spring integration label Aug 29, 2025
@mzellho
Copy link
Contributor Author

mzellho commented Aug 29, 2025

@FroMage thanks for all the feedback, I hope I didn't miss anything.

One more thing: I also found out that extensions/spring-data-jpa/runtime/src/main/java/io/quarkus/spring/data/runtime/RepositorySupport.java was already offering the same functionality by finding entities one by one based on their ID. I migrated it to use the new API and marked the second API that doesn't seem to bring any benefit to me anymore deprecated.

@mzellho mzellho requested a review from FroMage August 29, 2025 14:02

This comment has been minimized.

@mzellho mzellho force-pushed the findMultiple branch 2 times, most recently from b7e536c to afd8bcb Compare September 3, 2025 21:47
@mzellho mzellho requested a review from FroMage September 3, 2025 21:53
@FroMage
Copy link
Member

FroMage commented Sep 4, 2025

LGTM, do you mind merging your commits before we merge this?

This comment has been minimized.

@mzellho mzellho force-pushed the findMultiple branch 2 times, most recently from b318067 to 3b466ae Compare September 4, 2025 14:32

This comment has been minimized.

@FroMage
Copy link
Member

FroMage commented Sep 5, 2025

Do you mind rebasing on the latest main too?

@FroMage
Copy link
Member

FroMage commented Sep 5, 2025

Thanks

This comment has been minimized.

@FroMage
Copy link
Member

FroMage commented Sep 5, 2025

I think the test failures are related :-/

@mzellho
Copy link
Contributor Author

mzellho commented Sep 5, 2025

Hmmm, they were green some days ago :-( will look at it in the evening.

This comment has been minimized.

Copy link

github-actions bot commented Sep 5, 2025

😭 Deploy PR Preview failed.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@mzellho mzellho marked this pull request as draft September 5, 2025 23:12
Copy link
Member

@FroMage FroMage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you ready to take this out of draft?

@@ -24,13 +24,21 @@ public static List<?> findByIds(AbstractJpaOperations<PanacheQuery<?>> operation
result.add(byId);
}
}
return result;
return operations.findByIds(entityClass, result);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about this one? It appears we do findById on each ID, and then call findByIds with the results (which should be a list of entities, not ids).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FroMage this one in particular of course is incorrect and some leftover of pushing the current state of affairs before I reverted this PR to a draft. Unfortunately, there are a few problems, mainly caused by the vararg-API (some places use Iterables and calls end up in the wrong API). Also, when I last looked at it last Friday, I think I remember that on some places we have inconsistent and maybe confusing namings. I am quite busy at the moment, can only offer to continue with it in the evenings (but am absolutely willing to). But since we talk: I think it would be best to remove the vararg-API again (or give it another name) to move forward here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants