Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Problems with JPA 2, an Embeddable with Map and multiple usages in Entities
Problems with JPA 2, an Embeddable with Map and multiple usages in Entities [message #504383] Fri, 18 December 2009 15:34 Go to next message
Clemens D is currently offline Clemens D
Messages: 4
Registered: December 2009
Junior Member
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?
Re: Problems with JPA 2, an Embeddable with Map and multiple usages in Entities [message #507383 is a reply to message #504383] Wed, 13 January 2010 10:10 Go to previous message
Clemens D is currently offline Clemens D
Messages: 4
Registered: December 2009
Junior Member
It seems to be a bug in EclipseLink 2.0. I just downloaded a milestone of 2.0.1 and it works Razz

Clemens
Previous Topic:CLOB lenght problme on different databases
Next Topic:Incorrect SQL syntax for a "JOIN FETCH" JPQL
Goto Forum:
  


Current Time: Wed Sep 17 15:41:34 GMT 2014

Powered by FUDForum. Page generated in 0.03172 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software