简体   繁体   English

如何使用冬眠在我的分离中添加别名?

[英]How to add aliases in my disjunction using hibernate?

I'm writing a Criteria query using hibernate. 我正在使用休眠编写Criteria查询。 I have a DTO object and I have to generate a query using its fields. 我有一个DTO对象,必须使用其字段生成查询。 Everyting seems fine when I create a disjunction like this: 当我创建这样的析取时,一切似乎都很好:

Criteria c = s.createCriteria(Item.class);
        c.add(Restrictions.disjunction()
                .add(Restrictions.like("buyer", dto.getUser()))
                .add(Restrictions.like("rndEngineer", dto.getUser()))
                .add(Restrictions.like("logistics", dto.getUser()))
                .add(Restrictions.like("qaEngineer", dto.getUser()))
        );

But if I add an alias to my query to be able to do this: 但是,如果我在查询中添加一个别名就可以做到这一点:

Criteria c = s.createCriteria(Item.class);
        c.createAlias("wiEngineer", "we");
        c.add(Restrictions.disjunction()
                .add(Restrictions.like("buyer", dto.getUser()))
                .add(Restrictions.like("rndEngineer", dto.getUser()))
                .add(Restrictions.like("logistics", dto.getUser()))
                .add(Restrictions.like("qaEngineer", dto.getUser()))
                .add(Restrictions.like("we.sid", dto.getUser()))
        );

the where clause is fine but my result set is missing some elements. where子句很好,但是我的结果集缺少一些元素。 I think that Hibernate inner joins we on my item. 我认为Hibernate内部将我们加入了我的项目。 Can I make Hibernate left join my alias somehow? 我可以以某种方式让Hibernate离开加入我的别名吗? I googled on it but to no avail. 我用谷歌搜索,但无济于事。

Javadoc to the rescue: 抢救Javadoc

Criteria createAlias(String associationPath, String alias, int joinType) throws HibernateException 条件createAlias(String associationPath,String alias,int joinType)抛出HibernateException

Join an association using the specified join-type, assigning an alias to the joined association. 使用指定的联接类型联接关联,为联接的关联分配别名。

The joinType is expected to be one of CriteriaSpecification.INNER_JOIN (the default), CriteriaSpecification.FULL_JOIN, or CriteriaSpecification.LEFT_JOIN. joinType应该是CriteriaSpecification.INNER_JOIN(默认值),CriteriaSpecification.FULL_JOIN或CriteriaSpecification.LEFT_JOIN中的一种。

Why use Google when you have the javadoc and the Hibernate reference documentation available? 当您拥有Javadoc和Hibernate参考文档时,为什么还要使用Google?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM