Slt,
Voila j'ai un problème de duplicate collection role mapping lorsque j'essaye de générer mon sql à partir de mon script Ant. Le problème est sur le fichier Mapping.Droits.personne
La trace :
Dans la trace, on voit en vert qu'il y a deux imports de Droits. L'erreur pourrais venir de là, mais je sais pourquoi il y a ces deux imports.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 Buildfile: D:\Develloppement\Réalisations\Lafay\V2Lafay\build.xml clean: [delete] Deleting directory D:\Develloppement\Réalisations\Lafay\V2Lafay\bin [mkdir] Created dir: D:\Develloppement\Réalisations\Lafay\V2Lafay\bin copy-resources: [copy] Copying 12 files to D:\Develloppement\Réalisations\Lafay\V2Lafay\bin compile: [javac] Compiling 36 source files to D:\Develloppement\Réalisations\Lafay\V2Lafay\bin hbm2ddl: [hibernatetool] Executing Hibernate Tool with a Standard Configuration [hibernatetool] 1. task: hbm2ddl (Generates database schema) [hibernatetool] 16:15:02,564 INFO Environment:543 - Hibernate 3.3.1.GA [hibernatetool] 16:15:02,578 INFO Environment:576 - hibernate.properties not found [hibernatetool] 16:15:02,585 INFO Environment:709 - Bytecode provider name : javassist [hibernatetool] 16:15:02,594 INFO Environment:627 - using JDK 1.4 java.sql.Timestamp handling [hibernatetool] 16:15:02,709 INFO Configuration:1494 - configuring from file: hibernate.cfg.xml [hibernatetool] 16:15:02,791 INFO Configuration:586 - Reading mappings from resource : Mapping/Lieu.hbm.xml [hibernatetool] 16:15:02,902 INFO HbmBinder:322 - Mapping class: Mapping.Lieu -> Lieu [hibernatetool] 16:15:02,932 INFO Configuration:586 - Reading mappings from resource : Mapping/Parcourt.hbm.xml [hibernatetool] 16:15:02,962 INFO HbmBinder:322 - Mapping class: Mapping.Parcourt -> Parcourt [hibernatetool] 16:15:03,080 INFO Configuration:586 - Reading mappings from resource : Mapping/Exercices.hbm.xml [hibernatetool] 16:15:03,100 INFO HbmBinder:322 - Mapping class: Mapping.Exercices -> Exercices [hibernatetool] 16:15:03,158 INFO HbmBinder:836 - Mapping subclass: Mapping.EtirementExo -> Exercices [hibernatetool] 16:15:03,159 INFO HbmBinder:1441 - Mapping collection: Mapping.EtirementExo.etirement -> etirement [hibernatetool] 16:15:03,161 INFO HbmBinder:836 - Mapping subclass: Mapping.MusculationExo -> Exercices [hibernatetool] 16:15:03,162 INFO Configuration:586 - Reading mappings from resource : Mapping/Series.hbm.xml [hibernatetool] 16:15:03,174 INFO HbmBinder:322 - Mapping class: Mapping.Series -> Series [hibernatetool] 16:15:03,175 INFO HbmBinder:1441 - Mapping collection: Mapping.Series.mesRepetitions -> Repetitions [hibernatetool] 16:15:03,176 INFO Configuration:586 - Reading mappings from resource : Mapping/Niveau.hbm.xml [hibernatetool] 16:15:03,191 INFO HbmBinder:322 - Mapping class: Mapping.Niveau -> Niveau [hibernatetool] 16:15:03,192 INFO HbmBinder:1441 - Mapping collection: Mapping.Niveau.mesCaracteristiques -> Caracteristique [hibernatetool] 16:15:03,193 INFO Configuration:586 - Reading mappings from resource : Mapping/Seances.hbm.xml [hibernatetool] 16:15:03,208 INFO HbmBinder:322 - Mapping class: Mapping.Seances -> Seances [hibernatetool] 16:15:03,211 INFO HbmBinder:836 - Mapping subclass: Mapping.Footing -> Seances [hibernatetool] 16:15:03,212 INFO HbmBinder:836 - Mapping subclass: Mapping.Etirement -> Seances [hibernatetool] 16:15:03,212 INFO HbmBinder:1441 - Mapping collection: Mapping.Etirement.etirementExo -> Etir_EtirExo [hibernatetool] 16:15:03,213 INFO HbmBinder:836 - Mapping subclass: Mapping.Musculation -> Seances [hibernatetool] 16:15:03,214 INFO Configuration:586 - Reading mappings from resource : Mapping/Droits.hbm.xml [hibernatetool] 16:15:03,227 INFO HbmBinder:322 - Mapping class: Mapping.Droits -> Droits [hibernatetool] 16:15:03,228 INFO Configuration:586 - Reading mappings from resource : Mapping/Photos.hbm.xml [hibernatetool] 16:15:03,238 INFO HbmBinder:322 - Mapping class: Mapping.Photos -> Photos [hibernatetool] 16:15:03,239 INFO Configuration:586 - Reading mappings from resource : Mapping/Mensurations.hbm.xml [hibernatetool] 16:15:03,251 INFO HbmBinder:322 - Mapping class: Mapping.Mensurations -> Mensurations [hibernatetool] 16:15:03,252 INFO Configuration:586 - Reading mappings from resource : Mapping/Personnes.hbm.xml [hibernatetool] 16:15:03,271 INFO HbmBinder:322 - Mapping class: Mapping.Personnes -> Personnes [hibernatetool] 16:15:03,275 INFO HbmBinder:836 - Mapping subclass: Mapping.Administrateur -> Personnes [hibernatetool] 16:15:03,276 INFO HbmBinder:836 - Mapping subclass: Mapping.Utilisateur -> Personnes [hibernatetool] 16:15:03,277 INFO Configuration:1575 - Configured SessionFactory: Lafay [hibernatetool] 16:15:03,284 INFO Configuration:332 - Reading mappings from file: D:\Develloppement\Réalisations\Lafay\V2Lafay\src\Mapping\Droits.hbm.xml [hibernatetool] 16:15:03,295 INFO Mappings:161 - duplicate import: Mapping.Droits->Mapping.Droits [hibernatetool] 16:15:03,297 INFO Mappings:161 - duplicate import: Mapping.Droits->Droits [hibernatetool] 16:15:03,298 INFO HbmBinder:322 - Mapping class: Mapping.Droits -> Droits [hibernatetool] An exception occurred while running exporter #2:hbm2ddl (Generates database schema) [hibernatetool] To get the full stack trace run ant with -verbose [hibernatetool] Failed in building configuration when adding D:\Develloppement\Réalisations\Lafay\V2Lafay\src\Mapping\Droits.hbm.xml [hibernatetool] org.hibernate.InvalidMappingException: Could not parse mapping document from file D:\Develloppement\Réalisations\Lafay\V2Lafay\src\Mapping\Droits.hbm.xml [hibernatetool] org.hibernate.DuplicateMappingException: Duplicate collection role mapping Mapping.Droits.personne
Mon diagramme de classe (une partie) :
Hibernate.cfg.xml :
build.xml :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory name="Lafay"> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost/v1lafay</property> <property name="hibernate.connection.username">root</property> <mapping class="Lieu" resource="Mapping/Lieu.hbm.xml"/> <mapping class="Parcourt" resource="Mapping/Parcourt.hbm.xml"/> <mapping class="Exercices" resource="Mapping/Exercices.hbm.xml"/> <mapping class="Series" resource="Mapping/Series.hbm.xml"/> <mapping class="Niveau" resource="Mapping/Niveau.hbm.xml"/> <mapping class="Seances" resource="Mapping/Seances.hbm.xml"/> <mapping class="Droits" resource="Mapping/Droits.hbm.xml"/> <mapping class="Photos" resource="Mapping/Photos.hbm.xml"/> <mapping class="Mensurations" resource="Mapping/Mensurations.hbm.xml"/> <mapping class="Personnes" resource="Mapping/Personnes.hbm.xml"/> </session-factory> </hibernate-configuration>
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76 <project name="Lafay" default="compile"> <property name="source.dir" value="${basedir}/src"/> <property name="output.dir" value="${basedir}/bin"/> <property name="lib.dir" value="${basedir}/lib"/> <property name="generatedsqldir" value="${basedir}/Sql"/> <path id="classpath"> <fileset dir="${lib.dir}"> <include name="*.jar"/> </fileset> <pathelement path ="${output.dir}"/> </path> <target name="clean"> <delete dir="${output.dir}"/> <mkdir dir="${output.dir}"/> </target> <target name="compile" depends="clean, copy-resources"> <javac srcdir="${source.dir}" destdir="${output.dir}" classpathref="classpath"/> </target> <target name="copy-resources"> <copy todir="${output.dir}"> <fileset dir="${source.dir}"> <exclude name="**/*.java"/> </fileset> </copy> </target> <target name="run" depends="compile"> <java fork="true" classname="events.EventManager" classpathref="classpath"> <classpath path="output.dir"/> <arg value="${action}"/> </java> </target> <target name="hbm2java"> <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="classpath"/> <hibernatetool destdir="${source.dir}"> <classpath> <path refid="classpath"/> </classpath> <configuration> <fileset dir="${source.dir}"> <include name="**/*.hbm.xml"/> </fileset> </configuration> <hbm2java/> <hbm2dao/> </hibernatetool> </target> <target name="hbm2ddl" depends="compile" > <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="classpath"/> <hibernatetool destdir="${generatedsqldir}"> <classpath> <path refid="classpath"/> </classpath> <configuration configurationfile="${output.dir}/hibernate.cfg.xml"> <fileset dir="${source.dir}"> <include name="**/*.hbm.xml"/> </fileset> </configuration> <hbm2ddl drop="false" create="true" export="false" outputfilename="onlycreate.sql" format="true"/> <!--<hbm2ddl drop="true" create="false" export="false" outputfilename="onlydrop.sql" format="true"/> <hbm2ddl drop="true" create="true" export="false" outputfilename="dropandcreate.sql" format="true"/>--> </hibernatetool> </target> </project>
Droits.hbm.xml :
Personnes.hbm.xml :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="Mapping"> <class name="Droits" table="Droits"> <id column="Id" name="id" type="long"> <generator class="native"/> </id> <property column="unDroit" generated="never" lazy="false" name="unDroit" type="string"/> <!--// Une collection de personnes --> <set inverse="true" name="personne" sort="unsorted"> <key column="PersonneId" not-null="true"/> <one-to-many class="Personnes"/> </set> </class> </hibernate-mapping>
Lorsque je commente les lignes concernant le set dans le fichier Droits.hbm.xml, il me génére l'erreur suivante : Duplicate class/entity mapping Mapping.Droits
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
28
29
30
31
32
33
34
35 <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="Mapping"> <class name="Personnes" table="Personnes"> <id column="Id" name="id" type="long"> <generator class="native"/> </id> <discriminator column="PersonnesType" force="false" insert="true" not-null="true"/> <property column="Nom" generated="never" lazy="false" name="nom" type="string"/> <property column="Prenom" generated="never" lazy="false" name="prenom" type="string"/> <property column="Login" generated="never" lazy="false" name="login" type="string"/> <property column="Pass" generated="never" lazy="false" name="pass" type="string"/> <!-- // many-to-one vers DROITS --> <many-to-one class="Droits" column="Droit" name="Droit"/> <!-- // Sous class Administrateur --> <subclass discriminator-value="Administrateur" name="Administrateur" select-before-update="false"/> <!-- // Sous class Utilisateur --> <subclass discriminator-value="Utilisateur" name="Utilisateur" select-before-update="false"> <set cascade="persist.save-update" name="photos" sort="unsorted"> <key column="Id" not-null="true"/> <one-to-many class="Photos"/> </set> <set cascade="persist.save-update" name="mensurations" sort="unsorted"> <key column="Id" not-null="true"/> <one-to-many class="Mensurations"/> </set> <set cascade="persist.save-update" name="seances" sort="unsorted"> <key column="Id" not-null="true"/> <one-to-many class="Seances"/> </set> </subclass> </class> </hibernate-mapping>
J'ai regarder dans mes autres fichiers si je n'avais pas déclarer plusieurs fois la classe Droits, mais ce n'est pas le cas.
Je sais pas si ça aide, mais la génération automatique du code Java et DAO est correctement effectué.
Merci d'avance de votre aide.
Partager