Hql 查询map中key值?

最近做项目,由于常常要操作对象关联的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(); }

你可能感兴趣的:(table,query,Class)