I am trying to map an Entity to respective DTO list using HQL. Is there any way to select only the first element of an URL list and the latest date element from a Map?
Here is the query I am trying to build:
@Query("SELECT NEW ProductShownInListDto(p.name, p.price.getLatest(), p.productImages.get(1)) FROM Product p")
public List<ProductShownInListDto> getProductsToShowInList();
Here is the DTO:
public class ProductShownInListDto implements Serializable {
private String name;
private BigDecimal price;
private URL productImage;
}
Here is the product entity:
public class Product implements Serializable {
// [...] Other fields
@NotBlank
@Column(name = "name", nullable = false)
private String name;
@NotNull
@ElementCollection
private Map<LocalDate, BigDecimal> prices;
@NotNull
@ElementCollection
private List<URL> productImages;
}