Hibernate Native SQL Query retrieving multiple entities in join

痞子三分冷 提交于 2019-12-07 13:31:09

问题


Referencing with this answer to this correlated thread, the trick posted by ehrhardt works fine.

But, what I have to do if I have to join with multiple entities? for example:

List<Person> peopleWithBooks = session.createSQLQuery(
    "select {p.*}, {b.*}, {m.*} from person p, book b, magazine m where <complicated join>")
        .addEntity("p", Person.class)
        .addJoin("b", "p.books")
        .addJoin("m", "p.magazines")
        .addEntity("p", Person.class)
        .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
        .list();

Hibernate aggregates right the first join, but not the second (magazine entities are not grouped).

There are any tricks or there is a limit to join with only one correlated entity? And if I have to join with entities that have sub entities? (my goal is to retrieve all selected data with only one custom query)

来源:https://stackoverflow.com/questions/17423880/hibernate-native-sql-query-retrieving-multiple-entities-in-join

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