Comment mapper une carte & lt; String, Double & gt;
J'ai essayé
@ManyToMany(cascade = CascadeType.ALL)
Map<String, Double> data = new HashMap<String, Double>();
mais il produit de l'erreur :
org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.company.Klass.data[java.lang.Double]
at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1016)
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:567)
at org.hibernate.cfg.annotations.MapBinder$1.secondPass(MapBinder.java:80)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1130)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:296)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
une idée?
source d'informationauteur Nhaolio
Vous devez vous connecter pour publier un commentaire.
Bien, le message d'erreur est assez clair:
Double
n'est pas une entité. Si vous souhaitez mapper une collection d'éléments de base, utilisez laCollectionOfElement
annotation (veille prolongée) ou leElementCollection
annotation (à partir de JPA 2.0).Donc, en supposant que vous êtes en utilisant Hibernate Annotations 3.4, essayez ceci:
Ou, lors de l'utilisation de produits génériques:
Et si vous êtes en utilisant Hibernate Annotations 3.5+, préférez les annotations JPA 2.0:
Ou, lors de l'utilisation de produits génériques:
Références
Vous pouvez personnaliser complètement le résultat. Je pense que l'exemple ci-dessous montre tout:
Map
est définie à l'aide de laJoinTable
JoinColumn
dans leJoinTable
MapKey
Column