在休眠中创建内部查询 [英] Creating inner query in hibernate

查看:55
本文介绍了在休眠中创建内部查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在休眠状态的内部查询中添加set parameter()方法?

how to add a set parameter() metheod inside the inner query in hibernate?

我已经尝试这样做,但是已经出现错误

I have try to do like this but already have a errors

这是我的代码

Query query=session.createQuery("select eq.euipmentName,eq.type from Euipment eq where eq.id in(select euipment from Quotation qt where qt. supQuotation=:ids)");          
query.setParameter("ids",id);
list = (List<Euipment>)query.list();

推荐答案

我对您的查询做了一些更正: 1. qt. sup报价中有空格,我已删除 2.您子查询中的euipment没有别名,我添加qt

I've done some corrections about your query: 1. qt. supQuotation has a space, I've removed 2. euipment in you sub query haven't alias, I add qt

String hql = 
    "select eq.euipmentName,eq.type " +
    " from Euipment eq " +
    " where eq.id in (select qt.euipment from Quotation qt where qt.supQuotation = :ids)";

Query query = session.createQuery(hql);          
query.setParameter("ids",id);
list = (List<Euipment>)query.list();

告诉我,如果可以的话

如果不能,请在此处发布错误,并检查您是否在类中放入了休眠映射文件

If not OK, please post here the error, and check if you have put in hibernate mappping file your classes

这篇关于在休眠中创建内部查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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