开发者

JPA/Hibernate and messed up named parameters

开发者 https://www.devze.com 2022-12-28 00:06 出处:网络
My simple query looks like this on JPQL: SELECT COUNT(r) FROM 开发者_如何学Goorg.domain.Resource r WHERE r._parent = :parent AND r._metadata[:metadataKey] is not null

My simple query looks like this on JPQL:

SELECT COUNT(r) FROM 开发者_如何学Goorg.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?

0

精彩评论

暂无评论...
验证码 换一张
取 消