Home Spring Data JPA JPQL list in constructor
Reply: 0

Spring Data JPA JPQL list in constructor

user1209
1#
user1209 Published in April 22, 2018, 12:33 am

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?

entity layer:

PersonEntity table

EventEntity table

EventVisitorEntity table

  1. PersonEntity many to many EventEntity

  2. EventVisitorEntity interim table

domain layer:

class PersonInfo {
Person person;
List<PersonEvent> personEvent
...
}

Now I get all Person to take their ids and get the PersonEvent, using this query:

@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<PersonEvent> findEventsForPerson(List<Integer> ids);

It is possible to write one query to get persons with an personEvents ? in the constructor which is below:

public PersonInfo(Person person, List<PersonEvent> personEvents)
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.32122 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO