您的位置:首页 > 其它

Hql 查询map中key值?

2010-06-21 17:12 218 查看
最近做项目,由于常常要操作对象关联的map中的值和键,使得查找很慢,于是想了想能不能用hql直接查找map中的key然后比对呢?

最后功夫不负有心人,终于被我找到了。

类如下:

public class StaffCourseTable extends BaseEntity {

@OneToMany(mappedBy = "courseTable")
@MapKey(name = "section")
private Map<Section, StaffCourseTableEntry> sectionEntries = new HashMap<Section, StaffCourseTableEntry>();

}


查找没课的老师:

@SuppressWarnings("unchecked")
@Transactional(readOnly = true)
public List<Staff> findBySection(Section section) {
Query query = entityManager
.createQuery("select distinct table.staff from StaffCourseTable table  where (:section not in indices(table.sectionEntries) )");
query.setParameter("section", section);
return query.getResultList();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: