0

代码

        DetachedCriteria criteria2 = DetachedCriteria.forClass(MasterResult.class);
        criteria2.createAlias("masterCCHolders", "masterCCHolders", CriteriaSpecification.INNER_JOIN);
        criteria2.createAlias("masterFlights", "masterFlights", CriteriaSpecification.INNER_JOIN);
        criteria2.createAlias("masterPassengers", "masterPassengers", CriteriaSpecification.INNER_JOIN);
        criteria2.createAlias("masterVendors", "masterVendors", CriteriaSpecification.INNER_JOIN);

这正在生成以下查询

select
    this_.id as id49_4_,
    this_.adults as adults49_4_,
    this_.bookingdate as bookingd3_49_4_,
    this_.children as children49_4_,
    this_.depart_date as depart5_49_4_,
    this_.email1 as email6_49_4_,
    this_.fareprice as fareprice49_4_,
    this_.first_name as first8_49_4_,
    this_.infants as infants49_4_,
    this_.last_name as last10_49_4_,
    this_.phonenumber as phonenu11_49_4_,
    this_.selectiontime as selecti12_49_4_,
    this_.mastercurrentstatus as masterc13_49_4_,
    masterccho2_.master_booking_id as master4_49_6_,
    masterccho2_.id as id6_,
    masterccho2_.id as id47_0_,
    masterccho2_.first_name as first2_47_0_,
    masterccho2_.last_name as last3_47_0_,
    masterccho2_.master_booking_id as master4_47_0_,
    masterflig3_.master_booking_id as master5_49_7_,
    masterflig3_.id as id7_,
    masterflig3_.id as id50_1_,
    masterflig3_.direction as direction50_1_,
    masterflig3_.fromcode as fromcode50_1_,
    masterflig3_.master_booking_id as master5_50_1_,
    masterflig3_.tocode as tocode50_1_,
    masterpass4_.master_booking_id as master6_49_8_,
    masterpass4_.id as id8_,
    masterpass4_.id as id46_2_,
    masterpass4_.first_name as first2_46_2_,
    masterpass4_.last_name as last3_46_2_,
    masterpass4_.master_booking_id as master6_46_2_,
    masterpass4_.middle_name as middle4_46_2_,
    masterpass4_.type as type46_2_,
    mastervend5_.master_booking_id as master4_49_9_,
    mastervend5_.id as id9_,
    mastervend5_.id as id48_3_,
    mastervend5_.locator as locator48_3_,
    mastervend5_.master_booking_id as master4_48_3_,
    mastervend5_.name as name48_3_ 
from
    masterresult this_ 
left outer join
    masterccholder masterccho2_ 
        on this_.id=masterccho2_.master_booking_id 
left outer join
    masterflight masterflig3_ 
        on this_.id=masterflig3_.master_booking_id 
left outer join
    masterpassenger masterpass4_ 
        on this_.id=masterpass4_.master_booking_id 
left outer join
    mastervendor mastervend5_ 
        on this_.id=mastervend5_.master_booking_id 

查询返回 20 行,这很好,但这也会创建 masterResult 的 2o 个对象。

模型结构就像

MasterResult 包含

  • 一组masterCCHolders,
  • 一套masterFlights,
  • 一套masterPassengers,
  • masterVendors 集

怎么解决,这个问题?

1 MasterResult 包含

  • 2组masterCCHolders,
  • 2组masterFlights,
  • 5套masterPassengers,
  • 1 套 masterVendors,

所以总共2*2*5=20 条记录

我怎样才能拥有一个 masterResult 对象,其中包含一组大小为 2 的 masterCCholder、一组大小为 2 的 masterflights、一组大小为 5 的 masterpassengers 等等。

谢谢

4

1 回答 1

1
criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
于 2012-12-06T13:24:06.990 回答