5

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)

Community
  • 1
  • 1
fl4l
  • 1,580
  • 4
  • 21
  • 27

0 Answers0