2008-10-13 13 views
1

Je suis en train de cartographier une relation de ManyToMany entre 2 tables, les deux ayant des clés primaires compositesmapping Hibernate @ManyToMany avec les touches composites

LSFOCTB which primary key is composed of : LSFOC_CODSOC,LSFOC_CODLSC,LSFOC_CODFOC 

LSFORTB which primary key is composed of : LSFOR_CODSOC,LSFOR_CODLSC,LSFOC_CODFOR 

The table in charge of the ManyToMany relationship is : 

LSFCFTB, with : LSFCF_CODSOC,LSFCF_CODLSC,LSFCF_CODFOC,LSFCF_CODFOR 

Ainsi, dans le LSFOCTB de cartographie modèle de mise en veille prolongée, j'ai essayé:

@ManyToMany(targetEntity = package.LSFOCTB.class, cascade = { CascadeType.PERSIST, 
      CascadeType.MERGE }) 
    @JoinTable(name = "LSFCFTB", joinColumns = { 
      @JoinColumn(name = "LSFCF_CODLSC", referencedColumnName = "LSFOC_CODLSC"), 
      @JoinColumn(name = "LSFCF_CODFOC", referencedColumnName = "LSFOC_CODFOC"), 
      @JoinColumn(name = "LSFCF_CODSOC", referencedColumnName = "LSFOC_CODSOC") }, 
    inverseJoinColumns = { @JoinColumn(name = "LSFCF_CODLSC", referencedColumnName = "LSFOR_CODLSC"), 
      @JoinColumn(name = "LSFCF_CODFOR", referencedColumnName = "LSFOR_CODFOR"), 
      @JoinColumn(name = "LSFCF_CODSOC", referencedColumnName = "LSFOR_CODSOC") }) 

avant le getter. Mais ça ne marchera pas ... L'erreur, lorsque vous essayez d'accéder à la collection est lointaine:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [beans-dao.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Repeated column in mapping for collection: package.LSFOCTB.distantCollection column: LSFCF_CODLSC 

Ont déjà réussi à faire un travail de cartographie de mise en veille prolongée pour une relation ManyToMany? Si oui, quel est le problème avec ma cartographie? Nous vous remercions de votre aide!

+0

J'ai cherché des informations sur les pages suivantes: http://www.hibernate.org/hib_docs/annotations/reference/fr/html/entity.html#entity-hibspec chapitre: 2.2.5.3.3. Beaucoup à plusieurs et aussi: http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=78&t=003838 –

Répondre

1

Le problème semble être que vous créez une table de jointure avec 6 colonnes et qu'il y a des noms en double pour vos colonnes. Vous créez en fait 2 colonnes avec le nom LSFCF_CODLSC et 2 colonnes nommées LSFCF_CODFOR et 2 colonnes nommées LSFCF_CODSOC.

Je suggère que vous essayez ceci:

@JoinTable(name = "LSFCFTB", joinColumns = { 
        @JoinColumn(name = "LSFOC_LSFCF_CODLSC", referencedColumnName = "LSFOC_CODLSC"), 
        @JoinColumn(name = "LSFOC_LSFCF_CODFOC", referencedColumnName = "LSFOC_CODFOC"), 
        @JoinColumn(name = "LSFOC_LSFCF_CODSOC", referencedColumnName = "LSFOC_CODSOC") }, 
     inverseJoinColumns = { @JoinColumn(name = "LSFOR_LSFCF_CODLSC", referencedColumnName = "LSFOR_CODLSC"), 
        @JoinColumn(name = "LSFOR_LSFCF_CODFOR", referencedColumnName = "LSFOR_CODFOR"), 
        @JoinColumn(name = "LSFOR_LSFCF_CODSOC", referencedColumnName = "LSFOR_CODSOC") }) 

ou quelque chose de similaire (selon votre convention de nommage) pour donner chaque colonne un nom unique.

+0

Quels sont les noms des colonnes dans la table nommé LSFCFTB dans la base de données? name = "nom de la colonne existante" et referencedColumnName = "nom de la colonne référencée" –