我认为您应该能够大致执行JPQL或HQL。
SELECt count(p.colors) FROM Product AS p WHERe p.name = :name ... other search criteria etc
要么
SELECt count(c.products) FROM Color AS c WHERe c.name = :name .... other search criteria
从下面的评论,这应该工作:
Long colours=(Long) session.createQuery("select count(*) as cnt from Colour colour where colour.colourId in(select colours.colourId from Product product inner join product.colours colours where product.prodId=:prodId)").setParameter("prodId", prodId).uniqueResult();


