I'm pretty lost with mapping the following structure with JPA annotations.
+===========+ +====================+
| Offer | | Text |
+-----------+ 1 0..* +--------------------+
| id (pk) |-------------| textkey (pk) |
| namekey | | languagecode (pk) |
| ... | | text |
+===========+ | ... |
+====================+
So, each Offer has a name which is i18n-aware. As I have the same cases over and over in the application (Offer also has a i18n comment, Article has a i18n name, etc.) I want to have a Text entity with a composite primary key. For each key there are as many records as there are supported languages. Text samples:
+=====================================+
| textkey | languagecode | text |
+=====================================+
| offer5Name | en | foo |
| offer5Name | fr | bar |
| offer6Name | en | hello |
...
The Offer entity would store Text#textkey in its namekey column.
On the Java side I'd like Offer to have a Set of names or even better a Map of names so I could have a method like Text getName(String language)
instead of Set<Text> getNames()
.
What I already have is Text and its composite primary key TextPK:
@Entity
public class Text {
@EmbeddedId
private TextPK primaryKey;
@Column(name = "text")
private String text;
PK
@Embeddable
public class TextPK implements Serializable {
@Column(name = "textkey")
private Long key;
@Column(name = "languagecode")
@Enumerated(EnumType.STRING)
private LanguageCode languageCode;
Question: how do I annotate the 'names' member variable in the Offer class to get what I need?