0

我正在尝试从 HQL 创建一个标准。

简化的 HQL:

SELECT
    event.pkid,
    add.name
FROM Event event
LEFT JOIN event.addresses adds
JOIN adds.address add
WHERE adds is null
   or adds.addressType = 'EVENT'

我使用以下标准来生成等效查询。

criteria.createAlias("addresses", "adds",
            CriteriaSpecification.LEFT_JOIN)
            .createAlias("adds.address", "add",
            CriteriaSpecification.LEFT_JOIN)
            .setProjection(
                    Projections
                            .projectionList()
                            .add(Projections.property("pkid"))
                            .add(Projections
                                    .property("add.name")))
            .add(Restrictions.or(Restrictions.isNull("addresses"),
                    Restrictions.eq(
                            "adds.addressType.addressType",
                            "EVENT")));

但它会产生以下查询,

select
    this_.pkid as y0_,
    add2_.name as y1_
from event this_
left outer join event_address_map adds1_ on this_.pkid=adds1_.event_pkid
where (this_.pkid is null or adds1_.address_type=?)

不添加第二个连接。我究竟做错了什么?

提前致谢。

4

0 回答 0