Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provides query projection for Hibernate with Panache #6261

Closed
loicmathieu opened this issue Dec 19, 2019 · 8 comments · Fixed by #8563
Closed

Provides query projection for Hibernate with Panache #6261

loicmathieu opened this issue Dec 19, 2019 · 8 comments · Fixed by #8563
Labels
kind/enhancement New feature or request
Milestone

Comments

@loicmathieu
Copy link
Contributor

Description
Provides the same projection capabilities than for MongoDB with Panace.

See PR #4202

@loicmathieu loicmathieu added the kind/enhancement New feature or request label Dec 19, 2019
@FroMage
Copy link
Member

FroMage commented Dec 19, 2019

Note that I think we don't need it for all use-cases, because if we removed the bound for find it would just work. We should experiment.

@ahofmeister
Copy link

ahofmeister commented Dec 20, 2019

Is this going to be in the next version or anything? Just asking, no pressure. :)

loicmathieu added a commit to loicmathieu/quarkus that referenced this issue Jan 17, 2020
@FroMage
Copy link
Member

FroMage commented Jan 24, 2020

If we didn't have the bound on find (and its variants) we could do:

String name = Order.find("select name").firstResult();
long max = Order.find("select max(price)").firstResult();

Which is not about projections, but already goes a long way.

@FroMage
Copy link
Member

FroMage commented Jan 24, 2020

Actually perhaps even:

String name = Order.find("name").firstResult();
long max = Order.find("max(price)").firstResult();

Since this is not ambiguous with queries.

@loicmathieu
Copy link
Contributor Author

@FroMage if a query starts with select hibernate with Panache will use it as is so it will also needs to have a From clause ... same for your second example the current implementation will add a bad select clause.

Regarding the bound to find, if we didn't add one we will ends up using on of the two following construct for a basic typed usage (the same for your example, if you don't have a bound to find you need to specify the return type in a way) and I didn't like both :

Person person = (Person) Person.find("name", "Loic").firstResult(); // remove the bound and return Object
Person person = Person.<Person>find("name", "Loic").firstResult(); // remove the bound but allow a parameterized return type

Maybe I'm not seeing exactly what you propose ...

@FroMage
Copy link
Member

FroMage commented Jan 27, 2020

@FroMage if a query starts with select hibernate with Panache will use it as is so it will also needs to have a From clause ... same for your second example the current implementation will add a bad select clause.

Sure, but we can change that.

As for typing, we currently already have this issue, it's nothing new, and it's due to the way Java's type inference works. Right now the inferred bound will be PanacheEntity which is not much more useful. Another way to nudge it is:

PanacheQuery<String> q = Order.find("name");
String name = q.firstResult();

We could totally add a project as you suggest that would essentially return this but with a different type argument, which would indeed make Person.find("name").project(String.class).firstResult() be properly typed.

@loicmathieu
Copy link
Contributor Author

@FroMage for the records, Quarkus Spring Data compability layer now support returing a different type for a query, this has been implemented by #6691 the fun part is here : https://github.com/quarkusio/quarkus/pull/6691/files#diff-3e72c8149ec469f75ff8ffc49803d6f2R129-R154 it generates a mapper using PanacheQuery.stream().map() ...

@ebullient
Copy link
Contributor

@FroMage for the records, Quarkus Spring Data compability layer now support returing a different type for a query, this has been implemented by #6691 the fun part is here : https://github.com/quarkusio/quarkus/pull/6691/files#diff-3e72c8149ec469f75ff8ffc49803d6f2R129-R154 it generates a mapper using PanacheQuery.stream().map() ...

Yeah.. that was fun. I will admit to being quite pleased to get it working. ;)

loicmathieu added a commit to loicmathieu/quarkus that referenced this issue Mar 23, 2020
loicmathieu added a commit to loicmathieu/quarkus that referenced this issue Apr 13, 2020
loicmathieu added a commit to loicmathieu/quarkus that referenced this issue Apr 20, 2020
loicmathieu added a commit to loicmathieu/quarkus that referenced this issue Apr 20, 2020
loicmathieu added a commit to loicmathieu/quarkus that referenced this issue Apr 21, 2020
@FroMage FroMage added this to the 1.5.0 milestone Apr 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants