gpt4 book ai didi

java - 按yearWeek或week分组时出现IllegalStateException

转载 作者:太空宇宙 更新时间:2023-11-04 13:41:45 25 4
gpt4 key购买 nike

我有一个 QueryDSL JPAQuery,它应该按日历周分组。在其上调用 list(...) 时出现异常。只要我用year()替换所有出现的yearWeek(),它就可以正常工作。

java代码:

QCrmContact qCrmContact = QCrmContact.crmContact;
BooleanExpression whereClause = qCrmContact.beUserId.eq(beUserId).and(qCrmContact.crmContactTypeId.in(contactTypeIds));

JPAQuery query = new JPAQuery(entityManager);

query.from(qCrmContact).where(whereClause).orderBy(qCrmContact.createdDatetime.yearWeek().asc())
.groupBy(qCrmContact.createdDatetime.yearWeek(), qCrmContact.crmContactTypeId);
List<Tuple> rows = query.list(qCrmContact.createdDatetime.yearWeek(), qCrmContact.crmContactTypeId, qCrmContact.companyId.countDistinct());

异常(exception):

Exception occurred during processing request: No data type for node: org.hibernate.hql.internal.ast.tree.MethodNode
+-[METHOD_CALL] MethodNode: '('
| +-[METHOD_NAME] IdentNode: 'yearweek' {originalText=yearweek}
| \-[EXPR_LIST] SqlNode: 'exprList'
| \-[DOT] DotNode: 'crmcontact0_.CREATED_DATETIME' {propertyName=createdDatetime,dereferenceType=ALL,propertyPath=createdDatetime,path=crmContact.createdDatetime,tableAlias=crmcontact0_,className=de.xxx.cxlbackend.database.model.CrmContact,classAlias=crmContact}
| +-[ALIAS_REF] IdentNode: 'crmcontact0_.ID' {alias=crmContact, className=de.xxx.cxlbackend.database.model.CrmContact, tableAlias=crmcontact0_}
| \-[IDENT] IdentNode: 'createdDatetime' {originalText=createdDatetime}

java.lang.IllegalStateException: No data type for node: org.hibernate.hql.internal.ast.tree.MethodNode
+-[METHOD_CALL] MethodNode: '('
| +-[METHOD_NAME] IdentNode: 'yearweek' {originalText=yearweek}
| \-[EXPR_LIST] SqlNode: 'exprList'
| \-[DOT] DotNode: 'crmcontact0_.CREATED_DATETIME' {propertyName=createdDatetime,dereferenceType=ALL,propertyPath=createdDatetime,path=crmContact.createdDatetime,tableAlias=crmcontact0_,className=de.xxx.cxlbackend.database.model.CrmContact,classAlias=crmContact}
| +-[ALIAS_REF] IdentNode: 'crmcontact0_.ID' {alias=crmContact, className=de.xxx.cxlbackend.database.model.CrmContact, tableAlias=crmcontact0_}
| \-[IDENT] IdentNode: 'createdDatetime' {originalText=createdDatetime}

对我来说,使用一些 hack 并将 native SQL 传递给 Oracle 就可以了:

to_char(CREATED_DATETIME, 'IW.YYYY')

最佳答案

通过替换解决了

qCrmContact.createdDatetime.yearWeek()

StringExpression createdWeekYear = StringTemplate.create("to_char(CREATED_DATETIME, 'IW.YYYY')");

关于java - 按yearWeek或week分组时出现IllegalStateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31187842/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com