[英]HQL Object set from set
I got a Set<UserDTO>
collection in a not Hibernate object, and I got a User
domain entity in Hibernate. 我在非Hibernate对象中获得了
Set<UserDTO>
集合,并且在Hibernate中获得了User
域实体。
UserDTO
contains less information about user (only id and name) UserDTO
包含的有关用户的信息较少(仅ID和名称)
How can I select full Hibernate User Set
/ List
from the DTO object? 如何从DTO对象中选择完整的Hibernate用户
Set
/ List
?
Like this? 像这样?
Set<UserDTO> setDTO = .....
String hql = "FROM User WHERE id IN (:userDTO )";
Query query = entityManager.createQuery(hql);
query.setParameter("userDTO", setDTO);
return query.getResultList();
Thanks 谢谢
Almost. 几乎。 But you'd have to extract the IDs in a separate collection first:
但是您必须首先将ID提取到单独的集合中:
Set<Long> ids = new HashSet<Long>(setDTO.size());
for (UserDTO dto : setDTO) {
ids.add(dto.getId());
}
Then proceed with the query, and pass the ids
set as param. 然后继续进行查询,并传递设置为参数的
ids
。
不要忘记,您需要使用Query#setParameterList()而不是Query#setParameter。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.