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

The new Criteria API function support is not supported by other visitors #3187

Open
voronaam opened this issue Oct 17, 2024 · 0 comments
Open

Comments

@voronaam
Copy link

Expected Behavior

Consider a case where I have function defined in the DB returning true/false. I can now query its result in the select portion of the query, but not in the where. For example:

criteriaBuilder.and(queryFilter, criteriaBuilder.function("is_active", Boolean.class, root.get("status")))

Or using isTrue

criteriaBuilder.and(queryFilter, criteriaBuilder.isTrue(criteriaBuilder.function("is_active", Boolean.class, root.get("status"))))

Actual Behaviour

For the direct use in the query

Unexpected exception
java.lang.IllegalStateException: Unknown boolean expression: FunctionExpression{name='is_team_active', expressions=[RuntimePersistentPropertyPath{runtimePersistentProperty=Team.status}]}
        at io.micronaut.data.model.query.builder.sql.AbstractSqlLikeQueryBuilder2$SqlPredicateVisitor.visitPredicate(AbstractSqlLikeQueryBuilder2.java:1798)
        at io.micronaut.data.model.query.builder.sql.AbstractSqlLikeQueryBuilder2$SqlPredicateVisitor.visitConjunctionPredicates(AbstractSqlLikeQueryBuilder2.java:1824)
        at io.micronaut.data.model.query.builder.sql.AbstractSqlLikeQueryBuilder2$SqlPredicateVisitor.visitConjunctionPredicates(AbstractSqlLikeQueryBuilder2.java:1822)
        at io.micronaut.data.model.query.builder.sql.AbstractSqlLikeQueryBuilder2$SqlPredicateVisitor.visitConjunctionPredicates(AbstractSqlLikeQueryBuilder2.java:1822)
        at io.micronaut.data.model.query.builder.sql.AbstractSqlLikeQueryBuilder2$SqlPredicateVisitor.visitConjunctionPredicates(AbstractSqlLikeQueryBuilder2.java:1822)
        at io.micronaut.data.model.query.builder.sql.AbstractSqlLikeQueryBuilder2$SqlPredicateVisitor.visit(AbstractSqlLikeQueryBuilder2.java:1811)
        at io.micronaut.data.model.jpa.criteria.impl.predicate.ConjunctionPredicate.visitPredicate(ConjunctionPredicate.java:45)
        at io.micronaut.data.model.query.builder.sql.AbstractSqlLikeQueryBuilder2.buildWhereClause(AbstractSqlLikeQueryBuilder2.java:508)
        at io.micronaut.data.model.query.builder.sql.AbstractSqlLikeQueryBuilder2.buildSelect(AbstractSqlLikeQueryBuilder2.java:206)
        at io.micronaut.data.model.jpa.criteria.impl.AbstractPersistentEntityCriteriaQuery.buildQuery(AbstractPersistentEntityCriteriaQuery.java:117)

For the isTrue code:

Unexpected exception
java.lang.IllegalStateException: Expression is expected to be a property path! Got: FunctionExpression{name='is_team_active', expressions=[RuntimePersistentPropertyPath{runtimePersistentProperty=Team.status}]}
        at io.micronaut.data.model.jpa.criteria.impl.CriteriaUtils.requireBoolProperty(CriteriaUtils.java:86)
        at io.micronaut.data.model.jpa.criteria.impl.AbstractCriteriaBuilder.isTrue(AbstractCriteriaBuilder.java:421)
        at io.atono.backlogitem.BacklogItemFilter.makeQueryFilter(BacklogItemFilter.java:35)
        at io.micronaut.data.runtime.intercept.criteria.AbstractSpecificationInterceptor.lambda$getCriteriaQueryBuilder$5(AbstractSpecificationInterceptor.java:417)
        at io.micronaut.data.runtime.intercept.criteria.AbstractSpecificationInterceptor.buildInternalQuery(AbstractSpecificationInterceptor.java:340)
        at io.micronaut.data.runtime.intercept.criteria.AbstractSpecificationInterceptor.buildFind(AbstractSpecificationInterceptor.java:324)
        at io.micronaut.data.runtime.intercept.criteria.AbstractSpecificationInterceptor.preparedQueryForCriteria(AbstractSpecificationInterceptor.java:219)
        at io.micronaut.data.runtime.intercept.criteria.AbstractSpecificationInterceptor.findAll(AbstractSpecificationInterceptor.java:154)
        at io.micronaut.data.runtime.intercept.criteria.FindAllSpecificationInterceptor.intercept(FindAllSpecificationInterceptor.java:46)
        at io.micronaut.data.runtime.intercept.DataIntroductionAdvice.intercept(DataIntroductionAdvice.java:83)

Steps To Reproduce

No response

Environment Information

This problem does not depend on OS or Java version.

I am using "io.micronaut.data:micronaut-data-jdbc:4.9.5" thouogh, which I think is the latest at the time of writing.

The rest of Micronaut is from"io.micronaut.platform:micronaut-platform:4.6.3"

Example Application

No response

Version

4.6.3

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

1 participant