I have following entities:
Article
|
+- @Id long id
|
+- @ElementCollection Map<Language, Translation> translations
Translation
|
+- @Column String name
What I would like to achieve is to fetch a list of Articles, ordered by name in given Language.
Something like:
SELECT a FROM Article a
JOIN a.translations t WHERE t.language = ?
ORDER BY t.name
The problem is that when using t.language throws “could not resolve property” exception, even though the language column exists in the Translations database table.
How can I achieve this behaviour?
I think this is not supported by Hibernate. I would simply make Translation an entity rather than an embedded, and include a language field in the Translation entity.
The mapping would be
The association could also be bidirectional, and your query could then be much more logical and less dangerous, because it could return translations rather than articles: