JPA Criteria API: Multiple condition on LEFT JOIN

后端 未结 2 438
别那么骄傲
别那么骄傲 2020-12-10 06:34

I have a join reference like following for which the first join expression is constructed by the JPA API automatically.

CriteriaBuilder cb = entityManager.ge         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-10 07:18

    And Hibernate's Criteria API version 3.6 supports it too:

        Criteria c = session.createCriteria(Tuple.class);
    
        c.createAlias("demands", "d")
        .createAlias("d.metadata", "m", 
            Criteria.LEFT_JOIN, Restrictions.eq("m.type", "AFFECTATION_KEY"));
    

    Or you may want Restrictions.eqProperty() for that last bit. Note the under-appreciated version of createAlias() with the fourth parameter. Here is a quote from the documentation

    Parameters:

    • associationPath - A dot-seperated property path
    • alias - The alias to assign to the joined association (for later reference).
    • joinType - The type of join to use.
    • withClause - The criteria to be added to the join condition (ON clause)

    Hibernate API 3.6

提交回复
热议问题