Is there a way to have multiple SELECT NEW
statements in a jpql
query (Hibernate)?
This works for me:
@Query("SELECT NEW com.test.project.dto.ItemService(g,s,l,r) "
+" FROM Item g, Service s, Service l , Service r"
+" WHERE s.id = g.id"
+" AND s.location = l.name"
+" AND s.serviceType = 'type'"
+" AND l.serviceType = 'Location'"
+" AND l.area = r.name"
+" AND r.serviceType = 'Region'")
public List<Item> getAllItemsWithServices();
I get the expected Result in my DTO
.
@Component
public class ItemServiceDTO{
private Item item;
private Service serviceType;
private Service serviceLocation;
private Service serviceRegion;
public ItemServiceDTO(item item, Service serviceType, Service serviceLocation, Service serviceRegion) {
super();
this.item = item;
this.serviceType = serviceType;
this.serviceLocation = serviceLocation;
this.serviceRegion = serviceRegion;
}
But what I want is to have a new instance of Language
with its contructor.
For example like this:
@Query("SELECT NEW com.test.project.dto.ItemService(g,s,l,r), new LanguageDTO()"
+" FROM Item g, Service s, Service l , Service r"
Or in a subselect of ItemService
@Query("SELECT NEW com.test.project.dto.ItemService(g,s,l,r, new LanguageDTO())"
+" FROM Item g, Service s, Service l , Service r"
I also interested in using Map
and List
in my DTO Objects but I read thats not possible? Is that right?
My Spring boot application does start with errors while using the two examples.
At the end I want a Map of Map<List<Item>,Map<List<LanguageDTO>,List<ItemServiceDTO>>> map;
See Question&Answers more detail:
os