Я должен получить период дня рождения с помощью JPA Query Clause, используя МЕЖДУ .но не может использовать предложение ".between".дайте мне знать, где проблема.
Java8SpringBoot2.0.1HibernateEntityManager 5.2.17QueryDSL4.1.4MySQLConnector 5.1.46
MySQL Query
select floor(datediff(now(), birthDate) / 30) between 13 and 24
from Child
Положение о выдаче
JPAQueryFactory queryFactory = new JPAQueryFactory(this.em);
queryFactory
.select(
Expressions.numberTemplate(Long.class, "floor(datediff(now(), {0}) / 30)", child.birthDate)
// above expression have no problem.
.between(Expressions.constant(13), Expressions.constant(24))
)
.from(child).fetch();
Сообщение об ошибке
Unexpected AST: org.hibernate.hql.internal.ast.tree.BetweenOperatorNode
\-[BETWEEN] BetweenOperatorNode: 'between'
+-[METHOD_CALL] MethodNode: '('
| +-[METHOD_NAME] IdentNode: 'floor' {originalText=floor}
| \-[EXPR_LIST] SqlNode: 'exprList'
| \-[DIV] BinaryArithmeticOperatorNode: '/' {dataType=org.hibernate.type.IntegerType@771b47f4}
| +-[METHOD_CALL] MethodNode: '('
| | +-[METHOD_NAME] IdentNode: 'datediff' {originalText=datediff}
| | \-[EXPR_LIST] SqlNode: 'exprList'
| | +-[METHOD_CALL] MethodNode: '('
| | | +-[METHOD_NAME] IdentNode: 'now' {originalText=now}
| | | \-[EXPR_LIST] SqlNode: 'exprList'
| | \-[DOT] DotNode: 'child0_.birthDate' {propertyName=birthDate,dereferenceType=PRIMITIVE,getPropertyPath=birthDate,path=child.birthDate,tableAlias=child0_,className=com.example.Child,classAlias=child}
| | +-[ALIAS_REF] IdentNode: 'child0_.childId' {alias=child, className=com.example.Child, tableAlias=child0_}
| | \-[IDENT] IdentNode: 'birthDate' {originalText=birthDate}
| \-[NUM_INT] LiteralNode: '30'
+-[NAMED_PARAM] ParameterNode: '?' {name=1, expectedType=org.hibernate.type.IntegerType@771b47f4}
\-[NAMED_PARAM] ParameterNode: '?' {name=2, expectedType=org.hibernate.type.IntegerType@771b47f4}
Попробовал еще один пункт
queryFactory.select(
Expressions.booleanOperation(
Ops.BETWEEN,
Expressions.numberTemplate(Long.class, "floor(datediff(now(), {0}) / 30)", child.birthDate),
Expressions.constant(13),
Expressions.constant(24)
)
)
.from(child)
.fetch();