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

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


Another way

public List<Account> getAccountListByOrgName(String name){    return sessionFactory.getCurrentSession().createCriteria(Account.class)                .createAlias("book", "book")                .createAlias("book.organization", "organization")                .add(Restrictions.eq("organization.name", name))                .list();}


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();