I have folowing property in my hibenrate entity class:
@MapKeyJoinColumn(name = "language_code")
@LazyCollection(LazyCollectionOption.EXTRA)
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name = "text_translations", joinColumns = @JoinColumn(name = "text_id"))
private Map<Language, String> translations = new HashMap<>();
Now I want to query this entity and filter content of map by user's language (i.e. by map's key). I have folowing join in my query:
StringPath titleTran = new StringPath("title_tran");
from(entity).
.leftJoin(entity.translations, titleTran).fetch().where(?mapKey?.eq(userLanguage));
What I need is ?mapKey? to by path to language of titleTran path. Is this somehow possible in QueryDsl?
If you want to search for a given Map key, you can use the following HQL query:
select me
from MyEntity me
join me.translations tr
where
index(tr) = :lang
or with JPQL:
select me
from MyEntity me
join me.translations tr
where
key(tr) = :lang
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With