title: Spring Data JPA JPQL list in constructor
body: <p>In my application, a non-standard situation, I have a layer of entity in mysql, layer of dominain in controllers. My domain model contains a few entities, can this be integrated into one JPQL query?</p>
  
  <blockquote>
    <p>entity layer:</p>
  </blockquote>
  
  <p>PersonEntity table</p>
  
  <p>EventEntity table</p>
  
  <p>EventVisitorEntity table</p>
  
  <ol>
  <li><p>PersonEntity many to many EventEntity</p></li>
  <li><p>EventVisitorEntity interim table</p></li>
  </ol>
  
  <blockquote>
    <p>domain layer:</p>
  </blockquote>
  
  <pre><code>class PersonInfo {
  Person person;
  List&lt;PersonEvent&gt; personEvent
  ...
  }
  </code></pre>
  
  <p>Now I get all Person to take their ids and get the PersonEvent, using this query: </p>
  
  <pre><code>@Query("SELECT new domain.PersonEvent(ev.personId,ev.eventId,e.name,ev.state)" +
          " FROM EventVisitorEntity AS ev ,EventEntity AS e WHERE e.id = ev.eventId AND ev.personId IN (?1)")
  List&lt;PersonEvent&gt; findEventsForPerson(List&lt;Integer&gt; ids);
  </code></pre>
  
  <p>It is possible to write one query to get persons with an personEvents ?
  in the constructor which is below:</p>
  
  <pre><code>public PersonInfo(Person person, List&lt;PersonEvent&gt; personEvents)
  </code></pre>