How to join Multiple tables using hibernate criteria where entity relationship is not direct?

后端 未结 2 1880
庸人自扰
庸人自扰 2021-02-06 05:43

I have three entities. those are:

@Entity
public class Organization {
    @Id
    private long id;
    @Column
    priv         


        
2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-06 05:50

    you can do like this :

    Criteria accountCriteria = getCurrentSession().createCriteria(Account.class,"acc");
    Criteria bookCriteria =  accountCriteria .createCriteria("book","b");
    Criteria orgCriteria =  bookCriteria.createCriteria("organization","org");
    orgCriteria.add(Restrictions.eq("name", "XYZ"));
    
    ProjectionList properties = Projections.projectionList();
    properties.add(Projections.property("name"));
    properties.add(Projections.property("id"));
    
    accountCriteria.setProjection(properties);
    accountCriteria.list();
    

提交回复
热议问题