java - Mapping one-to-many relationship using QueryDSL SQL -
lets have 2 bean entities:
public class audit { private string code; private java.sql.timestamp creationdate; private string creatorid; private java.sql.timestamp deletiondate; private string description; private string id; private string name; private string notes; private short status; private list<auditparticipant> participants; }
and :
public class auditparticipant { private string auditid; private string department; private string id; private string name; private string notes; private string role; private string surname; }
... audit
can have 1..n participants
, how can use querydsl sql project list of participants audit bean (get participants belongs audit)?
the beans generated using querydsl code generation.
thanks
querydsl provides result aggregation functionality such cases http://www.querydsl.com/static/querydsl/3.1.1/reference/html/ch03s02.html#d0e1634
in case like
query.from(audit) .innerjoin(participant).on(...) .transform(groupby(audit.id).as(audit, list(participant)));
see these examples other groupby options https://github.com/mysema/querydsl/blob/master/querydsl-collections/src/test/java/com/mysema/query/collections/groupbytest.java