Map<ClassA,ClassB> problem

2 Messages Forum Options Options
Embed this topic
Permalink
Gerard
Map<ClassA,ClassB> problem
Reply Threaded MoreMore options
Print post
Permalink
I'm trying to map the followin classes:
public class Category implements java.io.Serializable {
    @Id
    @GeneratedValue
    private Long id;

    @OneToMany
    @JoinColumn(name = "CATEGORY_ID")
    @MapKey(name="language")
    private Map<Language, CategoryDescription> description = new HashMap<Language, CategoryDescription>();
    ...
}

public class Language implements java.io.Serializable {
    @Id
    @GeneratedValue
    private Long id;
    ...
}

public class CategoryDescription implements java.io.Serializable {
    @Id
    @GeneratedValue
    private Long id;
   
    @ManyToOne(optional=false)
    private Language language;
    ...
}

This worked for me using Hibernate and generated the following tables:
CATEGORY(ID,...)
LANGUAGE(ID,...)
CATEGORYDESCRIPTION(ID,LANGUAGE_ID,CATEGORY_ID,...)

Using OpenJPA I receive the following error:
<openjpa-1.1.0-r422266:657916 fatal user error> org.apache.openjpa.persistence.ArgumentException: Map field "at.idsoftware.vocabulary.data.Category.description" is attempting to use a map table, but its key is mapped by another field.  Use an inverse key or join table mapping.

How to map this?
Thanks!
Pinaki Poddar
Re: Map<ClassA,ClassB> problem
Reply Threaded MoreMore options
Print post
Permalink
Hi,
  OpenJPA can map this domain model using @PersistenceMap [1] annotation. Please see the manual for details:

[1] http://openjpa.apache.org/docs/latest/manual/manual.html#ref_guide_meta_jpa_persistent_map