SELECT
supplier_id FROM suppliers UNION ALL
SELECT supplier_id FROM orders;
我只是在查询的“UNION ALL”子句和查询的“UNION ALL”子句下创建两个条件。
但我的问题是我如何在条件中执行UNION ALL子句? 在此先感谢。
答案 0 :(得分:4)
有标准我认为hibernate不支持UNION ALL
但您可以使用两个条件查询来获得预期结果:
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.