how to perform union clause query with hibernate criteria api

后端 未结 1 906
[愿得一人]
[愿得一人] 2020-12-19 17:57
SELECT 
    supplier_id  FROM suppliers   UNION ALL 

SELECT     supplier_id  FROM orders;

i just creating two criteria above \"UNION ALL\" clause

相关标签:
1条回答
  • 2020-12-19 18:28

    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.
    
    0 讨论(0)
提交回复
热议问题