Hibernate AliasToBean with Collection

▼魔方 西西 提交于 2019-12-03 16:47:52

Just don't use any transformer and code the loop yourself:

List<Object[]> rows = query.list();
Parent parent = null;
List<Child> children = new ArrayList<Child>(rows.size());
for (Object[] row : rows) {
    parent = (Parent) row[0];
    children.add((Child) row[1]);
}
ParentChildWrapper result = new ParentChildWrapper(parent, children);

This makes 8 lines of trivial code instead of 1, but avoids reflection calls, and thus allows safe refactoring.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!