【发布时间】:2016-01-28 13:38:48
【问题描述】:
有没有办法在 jpql 查询(休眠)中包含多个 SELECT NEW 语句?
这对我有用:
@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();
我在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;
}
但我想要的是有一个 Language 的新实例及其构造函数。
例如这样:
@Query("SELECT NEW com.test.project.dto.ItemService(g,s,l,r), new LanguageDTO()"
+" FROM Item g, Service s, Service l , Service r"
或者在ItemService的子选择中
@Query("SELECT NEW com.test.project.dto.ItemService(g,s,l,r, new LanguageDTO())"
+" FROM Item g, Service s, Service l , Service r"
我也有兴趣在我的 DTO 对象中使用 Map 和 List,但我读到那不可能?对吗?
我的 Spring boot 应用程序在使用这两个示例时确实出现错误。
最后我想要一张Map<List<Item>,Map<List<LanguageDTO>,List<ItemServiceDTO>>> map;的地图
【问题讨论】:
-
您的 JPA 提供程序是什么(即 EclipseLink、Hibernate)?
-
抱歉,它的休眠
-
你好。我正在尝试使用新的运算符,但发现的资源很少。问题:您是否创建一个 jpa repo 接口并放置此语句: public List
- getAllItemsWithServices();在那个回购?将高度赞赏示例或对完整示例的引用。谢谢
标签: java spring hibernate jpa jpql