【发布时间】:2015-12-22 15:54:31
【问题描述】:
我正在尝试运行 JPA 查询以仅从我的实体返回特定字段,而不是整个实体(出于性能原因)。
在这个实体中是这样的:
@OneToMany(cascade = { CascadeType.ALL }, mappedBy = "helper", fetch = FetchType.EAGER)
@MapKeyColumn(name = "year")
public Map<Integer, DutyHistory> getDutyHistoryList() {
return dutyHistoryList;
}
我想在我的查询中从这张地图返回多个值,例如过去 3 年的 DutyHistory 对象的字段。
我的问题是,这个查询语法是什么?我将返回的值映射到 POJO,如下所示:
@Query(value = "SELECT new com.castlemon.helpers.dto.ReportHelper(h.helperId, h.firstName, h.secondName"
+ ", h.sex, h.service, h.dateOfBirth, h.schoolGroup, h.orientationRequired, h.notes as adminNotes "
+ ", h.primaryDuty.dutyName as primaryDuty, h.secondDuty, h.secondaryDuty.dutyName as secondaryDuty "
+ " WHERE h.travelling = 1")
public List<ReportHelper> getTravellingHelperDetails();
【问题讨论】:
标签: java jpa spring-data-jpa