SELECT supplier_id FROM suppliers UNION ALL
SELECT supplier_id FROM orders;
我只是在查询的“ UNION ALL”子句上方和查询的“ UNION ALL”子句上方创建两个条件。
但是我的问题是我如何在条件中执行UNION ALL子句?提前致谢。
我认为hibernate不支持条件,UNION ALL但是您可以使用两个条件查询来获得预期的结果:
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.