@MapKey sur un membre d'une clef composite
Bonjour,
nouvelle journée, nouveau problème... je voudrais réaliser une association OneToMany d'une classe container vers une série d'objets, le tout dans une HashMap dont la clef fait partie d'une clef composite de l'entité cible.
PLus concrètement :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| package com.etc.entity;
@Entity
@Table(name = "DEPARTEMENTS")
public class Departement extends Entite {
@EmbeddedId
private DepartmentPK pk; // with 3 fields, including "code" (as String) and their public getter/setter
@ManyToOne
private Societe societe;
public Societe getSociete() {
return societe;
}
public void setSociete(Societe societe) {
this.societe = societe;
}
@Column(insertable=false, updatable=false)
public String getCode() {
return pk.getCode();
}
}
package com.etc.entity; |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
@Entity
@Table(name = "SOCIETE")
public class Societe extends Entite {
public Societe() {
super();
departements = new HashMap<String, Departement>();
}
//...
@OneToMany(mappedBy = "societe")
@MapKey(name = "code")
private Map<String, Departement> departements;
public Map<String, Departement> getDepartements() {
return departements;
}
} |
Seulement, ce code là (trouvé sur le net, mais sur un forum hibernate!) ne fonctionne pas...
Citation:
Exception Description: The map key [code] on the entity class [class com.etc.entity.Departement] could not be found for the mapping [org.eclipse.persistence.mappings.OneToManyMapping[departements]].
Et c'est la même chose si j'enlève le getter getCode() et que je définis la MapKey avec "name=pk.code".
Je ne sais plus trop bien comment m'en sortir à ce point... Quelqu'un aurait une idée?