我的hibernate条件生成以下查询但我需要内部联接作为我查询中的第一个联接。
当前查询: -
select
count(*) as y0_
from
load this_
left outer join
load_carrier carrierrel2_
on this_.load_id=carrierrel2_.load_id
left outer join
carrier carrier3_
on carrierrel2_.carrier_id=carrier3_.carrier_id
left outer join
carrier_shipper_relation carriershi4_
on carrier3_.carrier_id=carriershi4_.carrier_id
and (
shipper1_.shipper_id=carriershi4_.shipper_id
)
inner join
shipper shipper1_
on this_.shipper_id=shipper1_.shipper_id
预期查询: -
select
count(*) as y0_
from
load this_
inner join
shipper shipper1_
on this_.shipper_id=shipper1_.shipper_id
left outer join
load_carrier carrierrel2_
on this_.load_id=carrierrel2_.load_id
left outer join
carrier carrier3_
on carrierrel2_.carrier_id=carrier3_.carrier_id
left outer join
carrier_shipper_relation carriershi4_
on carrier3_.carrier_id=carriershi4_.carrier_id
and (
shipper1_.shipper_id=carriershi4_.shipper_id
)
我的java类中的映射顺序
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="shipper_id")
private Shipper shipper;
@OneToMany(mappedBy = "load", fetch= FetchType.LAZY, cascade= CascadeType.ALL)
private List<LoadCarrierRelation> carriers = new ArrayList<LoadCarrierRelation>();
和我的Dao课程
criteria.createAlias("shipper", "shipper");
criteria.createAlias("carriers", "carrierrelation");
如何更改查询中的连接顺序。 它可以通过hql来完成,但我不想改变dao层的整个实现,因为它还包含很多其他映射。
答案 0 :(得分:0)
将条件更改为HQL查询。