Bonjour
J'ai le message suivantetFound shared references to a collection : ...
j'ai un gros doute d'un seul coup ...
Ma base dispose de 3 tables
Batch
Action
et BatchAction qui permet une relation n-n entre les deux premières.
J'ai mappé les objets comme suit :
Batch.hbm.xml
Action.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
17
18
19
20
21
22
23
24
25 ?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Project.Entities" assembly="Project"> <!-- Mappings for class 'Batch' --> <class name="Batch" table="Batch" lazy="false"> <!-- Identity mapping --> <id name="IdBatch" type="System.Int32" unsaved-value="null"> <column name="IdBatch" /> <generator class="native" /> </id> <!-- Simple mappings --> <property name="Name" /> <!-- Many-to-many mapping: Action --> <bag name="Actions" table="BatchAction" cascade="all" lazy="false"> <key column ="IdBatch" /> <many-to-many class="Action" column="IdAction" /> </bag> </class> </hibernate-mapping>
J'ai donc la collection de Batchs dans Action et la collection d'Actions dans Batch.
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 <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Project.Entities" assembly="Project"> <!-- Mappings for class 'Action' --> <class name="Action" table="Action" lazy="false"> <!-- Identity mapping --> <id name="IdAction" type="System.Int32" unsaved-value="null"> <column name="IdAction" /> <generator class="native" /> </id> <!-- Simple mappings --> <property name="Name" /> <!-- Simple mappings --> <property name="CreateDate" /> <!-- Simple mappings --> <property name="Localisation" /> <!-- Simple mappings --> <property name="Category" /> <!-- Simple mappings --> <property name="Constraints" /> <!-- Many-to-many mapping: Batch --> <bag name="Batchs" table="BatchAction" cascade="none" lazy="false"> <key column ="IdAction" /> <many-to-many class="Batch" column="IdBatch" /> </bag> </class> </hibernate-mapping>
Est-ce autorisé ? J'étais parti avec l'idée que NHibernate garantissait l'intégrité de ce type de définition
En gros si j'ai un Batch et une Action
J'ai un objet Batch instancier => batch
si je fait batch.Actions[0].Batchs[0] j'obtiens la référence de l'objet batch initial.
Est-ce bien cela ?
Merci de votre aide.
Partager