Java 在hibernate中创建内部查询
如何在hibernate中的内部查询中添加设置参数metheod 我试着这样做,但已经有一个错误 这是我的密码Java 在hibernate中创建内部查询,java,hibernate,Java,Hibernate,如何在hibernate中的内部查询中添加设置参数metheod 我试着这样做,但已经有一个错误 这是我的密码 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("id
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();
从
本机SQL查询的执行通过SQLQuery进行控制
接口,该接口通过调用Session.createSQLQuery获得
createQuery使用HQL语法创建查询对象。
createSQLQuery使用本机SQL语法创建查询对象。
因此,用createSQLQuery替换createSQLQuery以进行本机SQL查询。我对您的查询做了一些更正: 1.qt。Supquote有一个空格,我已经删除了 2.您子查询中的设备没有别名,我添加了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();
告诉我,如果可以的话
如果不正常,请在此处发布错误,并检查是否已将您的类放入hibernate映射文件中
Criteria c = getSession().createCriteria(Euipment.class, "e");
c.createAlias("e.quotation", "q"); // inner join by default
c.add(Restrictions.eq("q.supQuotation", id));
list = (List<Euipment>)c.list();
是什么让查询显示为SQL而不是HQL?亲爱的先生,我试过了,但也有一个例外,我不知道如何使用引号和括号,是rihgt吗?@Stewart:检查此链接:@tharaka:请更新您的问题,您得到的例外情况。@tharaka:您使用DB Console测试过您的查询吗?。我的错误是---Hibernate:从Equipment eq where eq.id中选择eq.Equipment eq.type。supquote=?“where子句”中的未知列“qt.supquote”-我的错误是-Hibernate:从Equipment eq where eq.id中选择eq.euipmentName,eq.type从Equipment eq where qt中选择Euipment。supquote=?“where子句”中的未知列“qt.supquote”-在数据库控制台上测试查询…然后尝试使用Hibernate