micronaut-data
micronaut-data copied to clipboard
AbstractCriteriaBuilder#function() not Supported
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!
@dstepanov is it possible that this ticket gets prioritized? My team is building a feature that will highly depend on this method.
Sure, it should use Hibernate's criteria builder in this case.
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.
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.
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?
Yes, looking to fix it in 4.3.0 https://github.com/micronaut-projects/micronaut-core/discussions/10137
Awesome! Thanks a lot!
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 🙏
If you use Hibernate it should use the criteria builder from it.
Not sure if that fix is released yet, maybe can try with the 4.4.1-SNAPSHOT?
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.
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.
I will take a look to support custom functions
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.
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.
Sure @dstepanov I've opened a feature request issue in #2975.