如何使用hibernate标准API执行联合子句查询 [英] how to perform union clause query with hibernate criteria api
本文介绍了如何使用hibernate标准API执行联合子句查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
SELECT
supplier_id FROM suppliers UNION ALL
SELECT supplier_id FROM orders;
我在查询的UNION ALL子句上面创建了两个条件,并在UNION ALL查询。
i just creating two criteria above "UNION ALL" clause of query and below "UNION ALL" clause of query.
但我的问题是我如何在条件中执行UNION ALL子句?
感谢提前。
but my question is how i perform UNION ALL clause in criteria? Thanks in Advance.
推荐答案
标准我认为hibernate不支持 UNION ALL
但您可以使用两个条件查询来获得预期结果:
with criteria I think hibernate does not support UNION ALL
but you can use two criteria queries to get the expected result:
Criteria cr1 = session.createCriteria(Suppliers.class);
cr1.setProjection(Projections.projectionList()
.add( Projections.property("supplier_id"), "supplier_id" )
);
List results1 = cr1.list();
Criteria cr2 = session.createCriteria(Orders.class);
cr2.setProjection(Projections.projectionList()
.add( Projections.property("supplier_id"), "supplier_id" )
);
List results2 = cr2.list();
results1.add(results2);
List unionAllList = results1; //this is the expected result.
这篇关于如何使用hibernate标准API执行联合子句查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文