We are using Postgresql with HStore extension and in our application. While working with one of
the requirement we came across a problem that we need to combine both JPA and HStore query and
select a HStore attribute as a result.
We tried couple of ways to solve this problem and at last we came across a solution by digging up Postgres HStore extension functions and Eclipse Link function execution API. I am writing this solution here hoping that this can be useful for others as well.
We tried couple of ways to solve this problem and at last we came across a solution by digging up Postgres HStore extension functions and Eclipse Link function execution API. I am writing this solution here hoping that this can be useful for others as well.
Solution
I am having entity called Person havingname and description as
regular attributes and fields is an HStore attribute having gender, role etc.
Working Eclipse Link query to find person role based on name and gender using
built-in HStore API functions fatchval and defined.
SELECT FUNCTION('fetchval', p.fields, 'role') as r FROM Person p WHERE p.name=:name AND FUNCTION('defined',
p.fields, 'gender') = true
Post a Comment
Post a Comment