Hi,
I have problems to implement the following mapping with JPA 2.
@Entity
public class LString implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name="lang")
private String language;
private String strValue;
...
}
implements a language-specific string. Now I want to wrap that into a MultiLanguage-String that is an Embeddable.
@Embeddable
public class MultiLanguageString implements Serializable {
private String defaultValue;
@OneToMany(cascade=CascadeType.ALL)
private Map<String,LString> lValues=new HashMap<String,LString>();
...
}
MultiLanguageString implements a String which has a default string value and additional language specific values (Ideally I thought it should be implemented with just a Map based on an ElementCollection within MultiLanguageString, but I know that this is not foreseen to work in JPA 2).
Now, I want to use MultiLanguageString in different classes (with the possibility of using it in the same class more than once).
@Entity
public class TestEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Embedded
@AttributeOverride(name="defaultValue", column=@Column(name="name"))
@AssociationOverride(name="lValues", joinTable=@JoinTable(name="testentity_names"))
private MultiLanguageString name;
@Embedded
@AttributeOverride(name="defaultValue", column=@Column(name="shortName"))
@AssociationOverride(name="lValues",joinTable=@JoinTable(name="testentity_shortnames"))
MultiLanguageString shortName;
...
}
If I try out this szenario I get an error message with a ClassCastException from EclipseLink
java.lang.ClassCastException: org.eclipse.persistence.internal.jpa.metamodel.EmbeddableTyp eImpl cannot be cast to org.eclipse.persistence.internal.jpa.metamodel
The szenario works, when I don't work with a Map but just with a Collection in MultiLanguageString. So, doesn't support JPA 2.0 such Maps as defined in MultiLanguageString in Embeddables or am I missing something?