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

Allow BlazeCriteriaQuery to apply to a BaseCriteriaBuilder #1557

Open
beikov opened this issue Oct 7, 2022 · 1 comment · May be fixed by #1659
Open

Allow BlazeCriteriaQuery to apply to a BaseCriteriaBuilder #1557

beikov opened this issue Oct 7, 2022 · 1 comment · May be fixed by #1659
Assignees
Labels
Milestone

Comments

@beikov
Copy link
Member

beikov commented Oct 7, 2022

As shown in the user question it is hard to compose JPA Criteria parts into a bigger query. My suggestion is to add the following to BlazeCriteriaQuery:

    public void applyToCriteriaBuilder(BaseCriteriaBuilder<T> builder);

This will allow users to compose a query like this:

CriteriaBuilder<Tuple> cb1 = factory.create(em, Tuple.class);
query1.applyToCriteriaBuilder( cb1 );
LeafOngoingSetOperationCriteriaBuilder<Tuple> cb2 = cb.unionAll();
query2.applyToCriteriaBuilder( cb2 );
FinalSetOperationCriteriaBuilder<Tuple> finalCb = cb2.endSet();
finalCb.orderByDesc("statusChangedAt").orderByDesc("id")

To fully solve the problem for the user we'd also need #1556 though.

beikov added a commit to beikov/blaze-persistence that referenced this issue Dec 29, 2022
@beikov beikov self-assigned this Dec 29, 2022
@beikov beikov added this to the 1.6.9 milestone Dec 29, 2022
@beikov beikov modified the milestones: 1.6.9, 1.6.10 Jun 14, 2023
@donalpmccarthy
Copy link

donalpmccarthy commented Jul 19, 2023

It would be super helpful if this apply functionality was available more generically. I have a requirement to support a filter on an analytic function - but these window functions aren’t supported in the where clause. The work around is either a select from a CTE or a sub query. It would be helpful if you already have a criteria query to be able to pass it into a fromWith or fromSubquery. So we end up with either:

select * from (…) a where a.rank = 1

or

with a as (…) select * from a where a.rank =1

In this example rank is a window function in the CTE or sub query of the form “rank() over (partition by … order by …) as rank”

When you already have a JPA criteria query but simply wish to wrap it in a parent select like above, I cannot see an easy way to achieve this without rebuilding the whole query from scratch using the BlazeCriteriaBuilder. Any help appreciated on this request!

thanks - d

@beikov beikov modified the milestones: 1.6.10, 1.6.11 Sep 23, 2023
@beikov beikov modified the milestones: 1.6.11, 1.6.12 Jan 10, 2024
@beikov beikov modified the milestones: 1.6.12, 1.6.13 Aug 2, 2024
@beikov beikov modified the milestones: 1.6.13, 2.0.1 Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants