问题
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> ();
: }
I would like to retrieve all Form records having a translation containing (!) « xxx ».
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) ")
Thanks for your help!
回答1:
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 + '%'")
If this doesn't work, you might have to append %
to the beginning and end of you variable :search
来源:https://stackoverflow.com/questions/32382842/like-query-on-values-of-map-elementcollection-in-entity-in-hql