内部加入HQL选择 [英] Inner join with select on HQL

查看:116
本文介绍了内部加入HQL选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用HQL做这样的事情:

I want to do something like that with HQL:

SELECT *
FROM tableA a
INNER JOIN (select fieldA, sum(fieldB) as sum from tableB) b
ON a.fieldA = b.fieldA and a.fieldC = b.sum;

但是,这给出了一个错误:

But this gives an error:

org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: (...

有什么办法可以使用HQL和Hibernate?

There is any way to make this using HQL and Hibernate?

推荐答案

试试 native SQL

try the native SQL solution approach:

需要先导入:

need toimport this first:

import org.hibernate.SQLQuery;

然后在代码中的某处:

SQLQuery query = session.createSQLQuery(
    "SELECT * FROM tableA a
    INNER JOIN 
    (SELECT fieldA, sum(fieldB) as sum from tableB) b
    ON a.fieldA = b.fieldA and a.fieldC = b.sum"
);

更多关于此连结

和HERE(
加入Hibernate查询语言)

more on this link
and HERE ( Joins in Hibernate Query Language)

这篇关于内部加入HQL选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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