Complex Hibernate Projections

前端 未结 4 745
野的像风
野的像风 2020-12-18 08:06

I want to ask, it is possible that I create query projections and criterion for more than one level deep? I have 2 model classes:

@Entity  
@Table(name = \"p         


        
4条回答
  •  一生所求
    2020-12-18 08:31

    Instead of creating Data Transfer Object (DTO)
    In projectionlist make below changes and it will work for you.

        ProjectionList projections = Projections.projectionList(); 
        projections.add(Projections.property("person.personID"), "personID");
        projections.add(Projections.property("person.wife"), "wife");
        projections.add(Projections.property("wife.name"));
    
        Criteria criteria = null; 
        criteria = getHandlerSession().createCriteria(Person.class,"person").createAlias("person.wife", "wife"); 
        criterion = Restrictions.eq("wife.age", 19);  
        criteria.add(criterion); 
        criteria.setProjection(projections);
        criteria.setResultTransformer(Transformers.aliasToBean(Person.class)); 
        return criteria.list();
    

提交回复
热议问题