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

AbstractCriteriaBuilder#function() not Supported #2693

Closed
elzayakm opened this issue Dec 15, 2023 · 17 comments
Closed

AbstractCriteriaBuilder#function() not Supported #2693

elzayakm opened this issue Dec 15, 2023 · 17 comments

Comments

@elzayakm
Copy link
Contributor

elzayakm commented Dec 15, 2023

Feature description

I would like to be able to build queries with JSON functions supported by my DB with Micronaut's QueryBuilder.

My repository implements the CoroutineJpaSpecificationExecutor and is configured to use the JpaQueryBuilderclass, as shown in the code snippet below.

@Repository
@RepositoryConfiguration(queryBuilder = JpaQueryBuilder::class)
interface ScheduledUpdateRepository : CoroutinePageableCrudRepository<X, Long>, CoroutineJpaSpecificationExecutor<X>

To do this, I need the function() method which is obviously not supported yet as shown in the code snippet below taken from the AbstractQueryBuilder class.

    @Override
    @NonNull
    public <T> Expression<T> function(@NonNull String name, @NonNull Class<T> type, @NonNull Expression<?>... args) {
        throw notSupportedOperation();
    }

If any additional info is required, please reach out to me on [email protected]. Thanks!

@elzayakm elzayakm changed the title Start supporting the AbstractCriteriaBuilder#function() method AbstractCriteriaBuilder#function() not Supported Dec 18, 2023
@elzayakm
Copy link
Contributor Author

@dstepanov is it possible that this ticket gets prioritized? My team is building a feature that will highly depend on this method.

@dstepanov
Copy link
Contributor

Sure, it should use Hibernate's criteria builder in this case.

@elzayakm
Copy link
Contributor Author

Do you have an example on how to use it? I am not able to get my Micronaut app configured to use it instead of the RuntimeCriteriaBuilder.

@dstepanov
Copy link
Contributor

For now, you can inject JpaRepositoryOperations and use getEntityManagerFactory, getEntityManagerFactory to build queries. I will try to fix it to be used in the repositories for the next release.

@elzayakm
Copy link
Contributor Author

Cool then! I prefer to wait for your release so that we don't pollute our code. Thanks a lot for your help!

I will follow-up regarding the status of this within two weeks after the new year. Is that ok?

@dstepanov
Copy link
Contributor

Yes, looking to fix it in 4.3.0 micronaut-projects/micronaut-core#10137

@elzayakm
Copy link
Contributor Author

Awesome! Thanks a lot!

@kareemelzayat
Copy link
Contributor

Hello @dstepanov, reaching out again regarding this. You told me you were looking to fix it in 4.3.0 released today. Still, I see that the method still throws an UnsupportedExcpetion. Are there any updates?

Thank you, and best regards 🙏

@dstepanov
Copy link
Contributor

If you use Hibernate it should use the criteria builder from it.

@radovanradic
Copy link
Contributor

Not sure if that fix is released yet, maybe can try with the 4.4.1-SNAPSHOT?

@kareemelzayat
Copy link
Contributor

kareemelzayat commented Jan 16, 2024

My repository extends the CoroutineJpaSpecificationExecutor, which allows implementations of the PredicateSpecification and QuerySpecification interfaces only. Those interfaces are always intercepted by the AbstarctSpecificationInterceptor, which I believe does NOT use the HibernateCriteriaBuilderDelegate, rather the AbstractCriteriaBuilder; which is what I am reporting in this ticket.

@voronaam
Copy link

voronaam commented May 17, 2024

Does anybody have a working example of using a different criteria builder? We are not using Hibernate and trying to work with JSONB in postgresql. So I either need to figure out how to use custom operator -> or function jsonb_extract_path

Since we have no Hibernate, the AbstractCriteriaBuilder is the only implementation I see on my class path.

I would very much appreciate a way to call a custom operator or a function. Please help.

Trying to add io.micronaut.data:micronaut-data-jpa library and injecting JpaRepositoryOperations to get a different criteria builder via jpaRepositoryOperations.getEntityManagerFactory().getCriteriaBuilder() only lead to this error:

No bean of type [io.micronaut.data.jpa.operations.JpaRepositoryOperations] exists.

@dstepanov
Copy link
Contributor

I will take a look to support custom functions

@varvay
Copy link

varvay commented Jun 4, 2024

This is pretty bad, even such simple operation like concat, coalesce, lower and upper aren't supported yet by the AbstractCriteriaBuilder. Luckily in my case, I was able to fulfil my need for "case-insensitive like" operation using the ilikeString method, but I believe sooner or later, these operations will be demanded, since not everyone are using Hibernate. I hope these operations will be available soon.

@dstepanov
Copy link
Contributor

I'm working on a query builder rewrite that should enable the quick addition of more criteria features.

Please create an additional issue of what operations are needed to assess what is wanted.

@varvay
Copy link

varvay commented Jun 7, 2024

Sure @dstepanov I've opened a feature request issue in #2975.

@dstepanov
Copy link
Contributor

Already supported in the latest version

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

No branches or pull requests

6 participants