Flo*_*Flo 6 hibernate localization hql
我想在我的模型中使用(可搜索)本地化,我想出了以下模型:
@Entity
public class Category {
...
@ElementCollection
//key = language code (e.g. 'en') and value = localized label
private Map<String, String> name;
...
}
Run Code Online (Sandbox Code Playgroud)
我想做的不是在特定的本地化中查询包含casesensitive针的类别(例如,英文名称为'%abc%')
我试过类似的东西
from Category where name.key = :locale and lower(name.value) like :text
Run Code Online (Sandbox Code Playgroud)
但失败了,无法解除引用标量集合元素异常.
现在hibernate文档说,我必须使用elements()和indices()来表示值和键.对于密钥,这将很容易使用:locale in indices(name),但我怎么能以casesensitive方式匹配此区域设置的一部分值?
为了防止hql与我的模型不可行,我还能如何模拟可搜索的本地化?
我终于想出了以下解决方案(实际上我很确定它也可以使用平面图而不是可嵌入对象来工作)
@Entity
public class Category {
...
@ElementCollection
@CollectionTable(name = "locale_category_name", joinColumns=@JoinColumn(name="id"))
List<Localization> name;
...
}
@Embeddable
public class Localization {
@NotNull
public String locale;
@NotNull
public String label;
}
Run Code Online (Sandbox Code Playgroud)
和查询(使用 join ... with ...)
from Category c join c.name l with (l.locale = :locale and lower(l.label) like :text)
Run Code Online (Sandbox Code Playgroud)
编辑:实际上我无法让它与地图一起使用,所以我毕竟使用的是 @Embeddable 解决方案
| 归档时间: |
|
| 查看次数: |
2443 次 |
| 最近记录: |