Hello,
I want to open the discussion again, to offers typed queries for Panache (Hibernate / JPA will be the target but ideally also for MongoDB).
Today, when using Hibernate with Panache, you must write your queries as String (using PanacheQL, JPQL, SQL or using a named query).
But for complex use case (think search engine for example), you may want to dynamically create the creary and having a types API instead of creating a String is a nice to have.
I saw this subject going back a few times these days so I really think we should do something about it (or decide we will not and close the 6 related issues).
We can do a lot of things:
1. Integrate with the JPA Criteria API (but the API is a little complex to use and doesn't match MongoDB usage) by allowing you to query with a CriteriaQuery.
2. Create a Specification API: we will need to design ours (there are plenty of existing one out)
3. Create an example API : this is very easy to do but doesn't offers complex query creation
4. Keep the status quo for one more year :(
Proposed implementation for example:
Person p = new Person();
p.lastName = "Mathieu";
PanacheQuery<Person> mathieus = Person.findByExample(Example.of(p));
Proposed implementation for specification (or criteria):
Criteria criteria = Criteria.eq("lastName", "Mathieu")
.and(Criteria.eq("firstName, "Loïc");
PanacheQuery<Person> me = Person.findByCriteria(criteria);
An alternative for 1. would be to allow querying with a JPA Query in addition to the existing String facilities, this will allow extending the querying facility to everything that can create JPA queries (MongoDB with Panache allow querying via a Document for such things).
Except for 4, we will need to add overload to list/stream/find/update/count/delete Panache methods to allow the new query functionality.
Let's the fight begin again :)
Regards,
Loïc