A类和B类是映射到其自己的数据库表的实体。 C类未映射并包含A和B的所有属性。是否可以构建HQL来填充C?
答案 0 :(得分:2)
是的,你可以。您可以使用Hibernates ResultTransformer:
List resultWithAliasedBean = s.createQuery(
"select e.student.name as studentName," +
" e.course.description as courseDescription" +
"from Enrolment as e")
.setResultTransformer( Transformers.aliasToBean(StudentDTO.class))
.list();
StudentDTO dto = (StudentDTO) resultWithAliasedBean.get(0);