简体   繁体   中英

HQL: how to find item in a subcollection by id

I'm trying to find the number of Events that have a given Cluster as member. I have the cluster id. (Event to Cluster is a ManyToMany.)

I have an HQL query like this:

select count(*) from Event e join e.clusters c where :id in (c.id)

I've also tried to put a subselect in the "in" part, but no luck.

Is there a way to do this in HQL?

select count(distinct e.id) 
from Event e join e.clusters c 
where c.id = :id 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM