Hibernate native SQL query - how to get distinct root entities with eagerly initialized one-to-many association
问题 I have two entities Dept and Emp (real case changed and minimized). There is 1:n association between them, i.e. properties Dept.empList and Emp.dept exist with respective annotations. I want to get List<Dept> whose elements are distinct and have collection empList eagerly initialized, using native SQL query. session.createSQLQuery("select {d.*}, {e.*} from dept d join emp e on d.id = e.dept_id") .addEntity("d", Dept.class) .addJoin("e", "d.empList") //.setResultTransformer(Criteria.DISTINCT