有没有一种方法可以用Hibernate/JPQL查询PostgreSQL hstore? [英] Is there a way to query a PostgreSQL hstore with Hibernate/JPQL?
问题描述
假设我有一个Hibernate/JPA实体,如下所示:
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.
是否有一种方法可以在JPQL查询中访问类似于此伪代码的hstore:
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)
推荐答案
Hibernate在许多数据库中提供了通用的查询抽象,因此很难抽象出非SQL语法.
Hibernate offers a common query abstraction across many DBs so a non-SQL syntax is hard to be abstracted out.
如果您确实需要ID,我会去进行本机查询以获取ID并使用它们来获取Hibernate实体.
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.
这篇关于有没有一种方法可以用Hibernate/JPQL查询PostgreSQL hstore?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!