我正在尝试实施基于客户的图表'年龄和系统注册。 我已经用SQL编写了代码并且它可以工作:
SELECT
[birthdate],
convert(date,creationDate)
FROM
[SELENIUM_TEST_DB].[dbo].[Client]
GROUP BY
birthdate, convert(date,creationDate)
如何在JPA中编写相同的查询?
这就是我所做的,但它不起作用:
public List<?> getDateForAgeGraph(){
Query q = em.createQuery("Select c.birthdate, convert(date,c.creationDate) From Client c group by c.birthdate ,convert(date,c.creationDate)");
return q.getResultList();
}
结果:
节点没有数据类型:org.hibernate.hql.internal.ast.tree.MethodNode
- [METHOD_CALL] MethodNode:&#39;(&#39;
+ - [METHOD_NAME] IdentNode:&#39;转换&#39; {originalText =转换}
- [EXPR_LIST] SqlNode:&#39; exprList&#39;
+ - [IDENT] IdentNode:&#39; date&#39; {originalText =日期}
- [DOT] DotNode:&#39; client0_.creationDate&#39; {propertyName的= creationDate,dereferenceType = PRIMITIVE,getPropertyPath = creationDate,路径= c.creationDate,tableAlias = client0_,类名= ge.shemo.model.client.Client,classAlias = C}
+ - [ALIAS_REF] IdentNode:&#39; client0_.clientID&#39; {alias = c,className = ge.shemo.model.client.Client,tableAlias = client0_}
- [IDENT] IdentNode:&#39; creationDate&#39; {originalText = creationDate}
答案 0 :(得分:0)
您不需要转换,因为JPA会为您处理所有数据转换。 creationDate的数据库类型是什么以及客户端实体中的类型是什么?