My simple query looks like this on JPQL:
SELECT COUNT(r) FROM org.domain.Resource r WHERE r._parent = :parent AND r._metadata[:metadataKey] is not null
But Hibernate SQL output looks like this (both for H2 and MySQL):
select
count(resource0_.id) as col_0_0_
from
resources resource0_,
resource_metadata metadata1_
where
resource0_.id=metadata1_.resource_id
and metadata1_.datum_key = ?
and resource0_.parent_id=?
and (
metadata1_.datum_value is not null
) limit ?
The problem here is the known bug in Hibernate which messes up prepared statement parameters. So in my case parent and key are mixed.
Any suggestions for a work around apart from native query?