javahibernatepostgresqljpahstore

Is there a way to query a PostgreSQL hstore with Hibernate/JPQL?


Assuming I have a Hibernate/JPA Entity like the following:

@Entity
public class FooEntity {

  ...

  @Type(type = "hstore")
  HashMap<String, String> tags;
}

... and the hstore Type is a simple UserType implementation from this resource.

Is there a way to access the hstore in a JPQL query similar to this Pseudocode:

SELECT f FROM FooEntity f WHERE f.tags CONTAINS KEY(:key)

Solution

  • Hibernate offers a common query abstraction across many DBs so a non-SQL syntax is hard to be abstracted out.

    I would go for a native query to fetch the ids and use those to get Hibernate entities if you really need those anyway.

    If you are only interested in projections than a native query is your best choice.