[JIRA] (HHH-13896) Issue with CriteriaBuilder with nested functions
by Ramy Siha (JIRA)
Ramy Siha ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNzUyYmQ2NDQ0... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-13896?atlOrigin=eyJpIjoiNzUyYm... ) HHH-13896 ( https://hibernate.atlassian.net/browse/HHH-13896?atlOrigin=eyJpIjoiNzUyYm... ) Issue with CriteriaBuilder with nested functions ( https://hibernate.atlassian.net/browse/HHH-13896?atlOrigin=eyJpIjoiNzUyYm... )
Issue Type: Bug Affects Versions: 5.4.12 Assignee: Unassigned Attachments: demo.hibernate.zip Components: hibernate-core Created: 15/Mar/2020 04:13 AM Labels: criteria hibernate jpa21 Priority: Major Reporter: Ramy Siha ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
I've registered a Postgres "jsonb_extract_path_text" function that can extract a specific Json key from JSONB column.
Now trying to apply count aggregate function on it, it produces QuerySyntaxException, seems that the function schema does not support braces
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery cq = cb.createQuery();
>From from = cq.from(Domain.class);
cq.select(cb.count(cb.function( "jsonb_extract_path_text" , String.class, from.get( "extra" ), cb.literal( "test1" ))));
TypedQuery query = em.createQuery(cq);
List list = query.getResultList();
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: expecting CLOSE, found '(' near line 1, column 22 [select count(function( 'jsonb_extract_path_text' , generatedAlias0.extra, 'test1' )) from com.example.demo.Domain as generatedAlias0]
at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:74) ~[hibernate-core-5.4.12.Final.jar:5.4.12.Final]
at org.hibernate.hql.internal.ast.ErrorTracker.throwQueryException(ErrorTracker.java:93) ~[hibernate-core-5.4.12.Final.jar:5.4.12.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:297) ~[hibernate-core-5.4.12.Final.jar:5.4.12.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:189) ~[hibernate-core-5.4.12.Final.jar:5.4.12.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:144) ~[hibernate-core-5.4.12.Final.jar:5.4.12.Final]
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:113) ~[hibernate-core-5.4.12.Final.jar:5.4.12.Final]
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:73) ~[hibernate-core-5.4.12.Final.jar:5.4.12.Final]
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:155) ~[hibernate-core-5.4.12.Final.jar:5.4.12.Final]
at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:604) ~[hibernate-core-5.4.12.Final.jar:5.4.12.Final]
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:716) ~[hibernate-core-5.4.12.Final.jar:5.4.12.Final]
... 43 common frames omitted
I've tested the same implementation with EclipseLink and it did not produce any errors, so I don't believe that this goes against JPA specifications.
( https://hibernate.atlassian.net/browse/HHH-13896#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-13896#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100121- sha1:a2b3dcc )
4 years, 9 months
[JIRA] (HV-1761) Not Work!! When i use custom validation,ALL version!!!
by deng A (JIRA)
deng A ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5e6cb37... ) *updated* an issue
Hibernate Validator ( https://hibernate.atlassian.net/browse/HV?atlOrigin=eyJpIjoiN2RiNGMyOTZjO... ) / Bug ( https://hibernate.atlassian.net/browse/HV-1761?atlOrigin=eyJpIjoiN2RiNGMy... ) HV-1761 ( https://hibernate.atlassian.net/browse/HV-1761?atlOrigin=eyJpIjoiN2RiNGMy... ) Not Work!! When i use custom validation,ALL version!!! ( https://hibernate.atlassian.net/browse/HV-1761?atlOrigin=eyJpIjoiN2RiNGMy... )
Change By: deng A ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5e6cb37... )
i learn springboot validation with hibernate-validator recently.
i write some custom validator
however it not work when i custom message
i want to valid a enum flag
relation class:
[https://github.com/hibernate/hibernate - validator/blob/master/engine/src/main/java/org/hibernate/validator/intern... - validator/blob/master/engine/src/main/java/org/hibernate/validator/internal/engine/messageinterpolation/ParameterTermResolver.java|smart - link]
- ---
{code:java}
/*
* Copyright (c) 2020. ascend 版权所有禁止转载。
*/
package cn.edu.zua.springbootdemo2.util.core.validation;
import cn.edu.zua.springbootdemo2.util.core.validation.bound.IntEnumValidatorForInteger;
import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.*;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* 说明:The annotated element must be a number of values .
*
* @author adeng 2020/3/14 10:12
*/
@Documented
@Constraint(validatedBy = {IntEnumValidatorForInteger.class})
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RetentionPolicy.RUNTIME)
@Repeatable(IntEnum.List.class)
public @interface IntEnum {
/**
* 合法值
*/
int[] value() default {};
String message() default "{javax.validation.constraints.IntEnum.message}";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
/**
* Defines several {@code @Email} constraints on the same element.
*
* @see IntEnum
*/
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RUNTIME)
@Documented
@interface List {
IntEnum[] value();
}
}
{code}
----
{code:java}
/*
* Copyright (c) 2020. ascend 版权所有禁止转载。
*/
package cn.edu.zua.springbootdemo2.util.core.validation.bound;
import cn.edu.zua.springbootdemo2.util.core.validation.IntEnum;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
/**
* 说明:
* 验证提供的值是否合法
*
* @author adeng 2020/3/14 15:21
*/
public class IntEnumValidatorForInteger implements ConstraintValidator<IntEnum, Integer> {
/**
* 合法值
*/
private int[] values;
/**
* Initializes the validator in preparation for
* {@link #isValid(Integer, ConstraintValidatorContext)} calls.
* The constraint annotation for a given constraint declaration
* is passed.
* <p>
* This method is guaranteed to be called before any use of this instance for
* validation.
* <p>
* The default implementation is a no-op.
*
* @param intEnum annotation instance for a given constraint declaration
*/
@Override
public void initialize(IntEnum intEnum) {
this.values = intEnum.value();
}
/**
* Implements the validation logic.
* The state of {@code value} must not be altered.
* <p>
* This method can be accessed concurrently, thread-safety must be ensured
* by the implementation.
*
* @param value object to validate
* @param context context in which the constraint is evaluated
* @return {@code false} if {@code value} does not pass the constraint
*/
@Override
public boolean isValid(Integer value, ConstraintValidatorContext context) {
for (int item : values) {
if (value == item) {
return true;
}
}
return false;
}
}
{code}
----
*controller*
{code:java}
/**
* 自定义int枚举校验
*
* @param input 输入
* @return 输出
*/
@GetMapping(value = "/get/custom/integer")
public CommonResult<Integer> getCustomInteger(@IntEnum(value = {0, 1}) Integer input) {
CommonResult<Integer> retResult = new CommonResult<>();
retResult.fillResult(CommonCode.SUCCESS(), input);
return retResult;
}
{code}
----
messages.properties
{code:java}
javax.validation.constraints.IntEnum.message=value not valid(valid values have {value})
{code}
----
error \ ! \ ! \ !
{code:java}
Caused by: java.lang.ClassCastException: class [I cannot be cast to class [Ljava.lang.Object; ([I and [Ljava.lang.Object; are in module java.base of loader 'bootstrap')
at org.hibernate.validator.internal.engine.messageinterpolation.ParameterTermResolver.interpolate(ParameterTermResolver.java:30)
at org.hibernate.validator.internal.engine.messageinterpolation.InterpolationTerm.interpolate(InterpolationTerm.java:64)
at org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.interpolate(ResourceBundleMessageInterpolator.java:159)
at org.hibernate.validator.messageinterpolation.AbstractMessageInterpolator.interpolateExpression(AbstractMessageInterpolator.java:519)
at org.hibernate.validator.messageinterpolation.AbstractMessageInterpolator.interpolateMessage(AbstractMessageInterpolator.java:408)
at org.hibernate.validator.messageinterpolation.AbstractMessageInterpolator.interpolate(AbstractMessageInterpolator.java:355)
at org.springframework.validation.beanvalidation.LocaleContextMessageInterpolator.interpolate(LocaleContextMessageInterpolator.java:51)
at org.hibernate.validator.internal.engine.validationcontext.AbstractValidationContext.interpolate(AbstractValidationContext.java:313)
... 75 common frames omitted
{code}
( https://hibernate.atlassian.net/browse/HV-1761#add-comment?atlOrigin=eyJp... ) Add Comment ( https://hibernate.atlassian.net/browse/HV-1761#add-comment?atlOrigin=eyJp... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100121- sha1:a2b3dcc )
4 years, 9 months