查询GORM中的计算字段 [英] Querying computed fields in GORM

查看:516
本文介绍了查询GORM中的计算字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用GORM查询以下HQL:

I am trying to query the following HQL using GORM:

MailMessage.executeQuery("toId, count(toId) from (SELECT  toId, threadId FROM MailMessage as m WHERE receiveStatus = 'u' GROUP BY threadId, toId) as x group by x.toId")

问题在于 count(toId)是一个计算字段不存在于 MailMessage 并且我正在使用子查询。

The problem is that count(toId) is a computed field doesn't exist in MailMessage and that I am using a subquery.

我得到以下错误: java.lang.IllegalArgumentException:要遍历的节点不能为null!理想情况下,我想要使用一个通用的executeQuery,它将返回任何类型的数据。有没有这样的事情?

I get the following error: java.lang.IllegalArgumentException: node to traverse cannot be null! Ideally, I would like to use a generic executeQuery which will return data of anytype. Is there such a thing?

推荐答案

我回答我自己的问题。唯一的方法是执行原始SQL并且不使用HQL。不幸的是,我无法想出如何用子查询和计算字段执行复杂的查询。

I am answering my own question. The only way to do this is to execute raw SQL and not use HQL. Unfortunately, there is no way that I figured out how to execute a complicated query with a subquery and computed field.

我在这里使用了示例: Grails查询不使用GORM

I used the example here: Grails query not using GORM

这篇关于查询GORM中的计算字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆