Let's consider the following code
@Embeddable public class MultiLanguageString { private String defaultValue; @ElementCollection private Map<String, String> otherValues;
// getters, setter, ... }
which models a String that can beside a defaultValue have values in other languages (i.e. key of the map is something like "en" or "de").
Then I want to use this multiple times in an entity.
@Entity public class MultiLangDataSet { @Embedded @AttributeOverride(name="defaultValue", column=@Column(name="DEFAULTNAME")) @AssociationOverride(name="otherValues", joinTable=@JoinTable(name="OVALUESNAME") private MultiLanguageString name;
@Embedded @AttributeOverride(name="defaultValue", column=@Column(name="SDESCRIPTION")) @AssociationOverride(name="otherValues", joinTable=@JoinTable(name="OVALUESDESC") private MultiLanguageString shortDescription;
// getters, setters, ... }
Multiple usage of MultiLanguageString within an entity doesn't seem to be possible with JPA 2 because while I can disambiguate the "defaultValue" field with AttributeOverride it's not possible to do the same with the map field otherValues (AssociationOverride doesn't seem to work with ElementCollection, when I try to change the collection table name with it). But the example works, when I have only one MultiLanguageString object in MultiLangDataSet.
Is this a design flaw or a bug of JPA 2 or am I missing something? Does Hibernate itself provides a mapping extension that handles this usage szenario?
Clemens
|