在HQL中的实体上查询Map ElementCollection的值 [英] LIKE query on values of Map ElementCollection in entity in HQL
问题描述
我有一个名为«Form»的实体,其中包含(key/value)=(语言代码/翻译)的Map«details»:
I have an entity named « Form » that contains a Map « details » of (key/value)=(language code/translation) :
@Entity
class Form {
:
@ElementCollection(fetch = FetchType.EAGER)
@MapKeyColumn(name = "language", length = 50, nullable = false)
@MapKeyEnumerated(EnumType.STRING)
@Column(name = "value", length = 150)
private final Map<Language, String> details = new HashMap<Language, String> ();
: }
我想检索所有翻译后包含(!)«xxx»的表格记录.
I would like to retrieve all Form records having a translation containing (!) « xxx ».
以下子句检索«Form»,其中地图包含一个«value»,其值与搜索流完全相同.不过,我想应用类似条件.
The following clause retrieves « Form » where the map contains a « value » whose value is exactly equals the search stream. I would like however apply a LIKE condition.
@Query("SELECT f FROM Form f JOIN f.details d WHERE KEY(d) = :language AND :search IN elements(d) ")
感谢您的帮助!
推荐答案
在SQL中,%
是LIKE
运算符中使用的通配符.您的查询将类似于:
In SQL, %
is a wildcard used in the LIKE
operator. Your query would be something like:
@Query("SELECT f FROM Form f JOIN f.details d
WHERE KEY(d) = :language
AND VALUE(d) LIKE '%' + :search + '%'")
如果这不起作用,则可能必须将%
附加到变量:search
If this doesn't work, you might have to append %
to the beginning and end of you variable :search
这篇关于在HQL中的实体上查询Map ElementCollection的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!