Bonjour,
je rencontre des difficultés pour mapper mes objets avec NHibernate.
J'ai donc créé trois tables : contrat - client - interimaire.

La clef primaire de la table contrat se compose de trois attributs :
NumContrat - NumClient - NumInterimaire.

Mapping de contrat :

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
 
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <!--Built with MyGeneration/Template/NHibernate (c) by OHM (alvy77@hotmail.com)
based on NHibernate lujan99 0.9.20 (c) by <a href="mailto:lujan99@usa.net">lujan99@usa.net</a>-->
  <class name="adecco.Entities.Contrat,adecco" table="contrat" lazy="false">
    <composite-id name="Id" class="adecco.Entities.ContratId,adecco">
      <key-property name="NumContrat" column="num_contrat" type="int" />
 
 
      <!-- <key-property name="ClientNumClient" column="client_num_client" type="int" /> -->
      <key-many-to-one name="ClientNumClient"
           column="client_num_client"         
           class="Client"
           unique="true"
           not-null="true"/>
 
 
      <!-- <key-property name="InterimaireMatricule" column="interimaire_matricule" type="int" />-->
      <key-many-to-one name="InterimaireMatricule"
          column="interimaire_matricule"
          class="Interimaire"
          unique="true"
          not-null="true"/> 
 
    </composite-id>
    <property type="int" not-null="true" name="TypeAvenantId" column="type_avenant_id" />
    <property type="int" not-null="true" name="QualificationId" column="qualification_id" />
    <property type="int" not-null="true" name="StatutContratId" column="statut_contrat_id" />
    <property type="DateTime" not-null="true" name="DateAvenant" column="date_avenant" />
    <property type="boolean" not-null="true" name="TacheRisque" column="tache_risque" />
    <property type="boolean" not-null="true" name="Intemperie" column="intemperie" />
    <property type="boolean" not-null="true" name="Risque" column="risque" />
    <property type="boolean" not-null="true" name="SurveillanceMedical" column="surveillance_medical" />
 
  </class>
</hibernate-mapping>
Mapping de client :

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
 
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <!--Built with MyGeneration/Template/NHibernate (c) by OHM (alvy77@hotmail.com)
based on NHibernate lujan99 0.9.20 (c) by <a href="mailto:lujan99@usa.net">lujan99@usa.net</a>-->
  <class name="adecco.Entities.Client,adecco" table="client" lazy="false">
    <id name="NumClient" column="num_client" type="int">
      <generator class="native" />
    </id>
    <property type="int" not-null="true" name="SecteurActiviteId" column="secteur_activite_id" />
    <property type="int" not-null="true" name="RaisonSocialId" column="raison_social_id" />
    <property type="string" length="255" name="Adresse" column="adresse" />
    <property type="string" length="14" name="NumSiret" column="num_siret" />
    <property type="string" length="10" name="Telephone" column="telephone" />
 
 
  </class>
</hibernate-mapping>
Mapping de Interimaire :

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
 
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <!--Built with MyGeneration/Template/NHibernate (c) by OHM (alvy77@hotmail.com)
based on NHibernate lujan99 0.9.20 (c) by <a href="mailto:lujan99@usa.net">lujan99@usa.net</a>-->
  <class name="adecco.Entities.Interimaire,adecco" table="interimaire" lazy="false">
    <id name="Matricule" column="matricule" type="int">
      <generator class="native" />
    </id>
    <property type="int" not-null="true" name="RoutagePaieId" column="routage_paie_id" />
    <property type="string" not-null="true" length="20" name="Nom" column="nom" />
    <property type="string" not-null="true" length="255" name="LieuEditionContrat" column="lieu_edition_contrat" />
    <property type="DateTime" not-null="true" name="DateNaissance" column="date_naissance" />
    <property type="boolean" not-null="true" name="Retraite" column="retraite" />
 
  </class>
</hibernate-mapping>
Voici l'erreur que me balance la console :

L'application démarre...



System.TypeInitializationException: Une exception a été levée par l'initialiseur
de type pour 'adecco.NHibernateHelper'. ---> NHibernate.MappingException: adecc
o.Mapping.Contrat.hbm.xml(14,12): XML validation error: L'attribut 'unique' n'es
t pas déclaré. ---> System.Xml.Schema.XmlSchemaException: L'attribut 'unique' n'
est pas déclaré.
à System.Xml.Schema.SchemaInfo.GetAttributeXsd(SchemaElementDecl ed, XmlQuali
fiedName qname, Boolean& skip)
à System.Xml.Schema.XsdValidator.ValidateStartElement()
--- Fin de la trace de la pile d'exception interne ---
à NHibernate.Cfg.Configuration.LogAndThrow(MappingException me)
à NHibernate.Cfg.Configuration.ValidationHandler(Object o, ValidationEventArg
s args)
à System.Xml.Schema.BaseValidator.SendValidationEvent(XmlSchemaException e, X
mlSeverityType severity)
à System.Xml.Schema.XsdValidator.ValidateStartElement()
à System.Xml.Schema.XsdValidator.ProcessElement(Object particle)
à System.Xml.Schema.XsdValidator.ValidateElement()
à System.Xml.Schema.XsdValidator.Validate()
à System.Xml.XmlValidatingReaderImpl.ProcessCoreReaderEvent()
à System.Xml.XmlValidatingReaderImpl.Read()
à System.Xml.XmlValidatingReader.Read()
à System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace)
à System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
à System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preser
veWhitespace)
à System.Xml.XmlDocument.Load(XmlReader reader)
à NHibernate.Cfg.Configuration.LoadMappingDocument(XmlTextReader hbmReader, S
tring name)
à NHibernate.Cfg.Configuration.AddXmlReader(XmlTextReader hbmReader, String n
ame)
à NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String n
ame)
à NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly)
à NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly)
à NHibernate.Cfg.Configuration.AddAssembly(String assemblyName)
à NHibernate.Cfg.Configuration.DoConfigure(XmlDocument doc)
à NHibernate.Cfg.Configuration.Configure(XmlTextReader reader)
à NHibernate.Cfg.Configuration.Configure(String fileName)
à NHibernate.Cfg.Configuration.Configure()
à adecco.NHibernateHelper..cctor() dans D:\Mes Documents\Visual Studio 2008\P
rojects\adecco\adecco\NHibernateHelper.cs:ligne 22
--- Fin de la trace de la pile d'exception interne ---
à adecco.NHibernateHelper.GetCurrentSession()
à adecco.Manager.ContratManager..ctor() dans D:\Mes Documents\Visual Studio 2
008\Projects\adecco\adecco\Manager\ContratManager.cs:ligne 19
à adecco.Program.Main(String[] args) dans D:\Mes Documents\Visual Studio 2008
\Projects\adecco\adecco\Program.cs:ligne 33



L'application est fermée!

J'ai bien entendu essayer d'enlever la propriete "Unique". Une erreur apparait alors. Et on me demande d'enlever le propriété "not-null".

Ensuite une erreur apparait :

L'application démarre...



System.TypeInitializationException: Une exception a été levée par l'initialiseur
de type pour 'adecco.NHibernateHelper'. ---> NHibernate.MappingException: Could
not compile the mapping document: adecco.Mapping.Contrat.hbm.xml ---> NHibernat
e.MappingException: unknown class Client ---> System.TypeLoadException: Could no
t load type Client. Possible cause: no assembly name specified.
à NHibernate.Util.ReflectHelper.TypeFromAssembly(AssemblyQualifiedTypeName na
me, Boolean throwOnError)
à NHibernate.Util.ReflectHelper.ClassForName(String name)
à NHibernate.Cfg.HbmBinder.ClassForFullNameChecked(String fullName, String er
rorMessage)
--- Fin de la trace de la pile d'exception interne ---
à NHibernate.Cfg.HbmBinder.ClassForFullNameChecked(String fullName, String er
rorMessage)
à NHibernate.Cfg.HbmBinder.ClassForNameChecked(String name, Mappings mappings
, String errorMessage)
à NHibernate.Cfg.HbmBinder.GetClassName(String unqualifiedName, Mappings mode
l)
à NHibernate.Cfg.HbmBinder.GetClassName(XmlAttribute att, Mappings model)
à NHibernate.Cfg.HbmBinder.GetEntityName(XmlNode elem, Mappings model)
à NHibernate.Cfg.HbmBinder.BindManyToOne(XmlNode node, ManyToOne model, Strin
g defaultColumnName, Boolean isNullable, Mappings mappings)
à NHibernate.Cfg.HbmBinder.BindComponent(XmlNode node, Component model, Type
reflectedClass, String className, String path, Boolean isNullable, Mappings mapp
ings)
à NHibernate.Cfg.HbmBinder.BindRootClass(XmlNode node, RootClass model, Mappi
ngs mappings)
à NHibernate.Cfg.HbmBinder.BindRoot(XmlDocument doc, Mappings mappings)
à NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc)
--- Fin de la trace de la pile d'exception interne ---
à NHibernate.Cfg.Configuration.LogAndThrow(MappingException me)
à NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc)
à NHibernate.Cfg.Configuration.ProcessMappingsQueue()
à NHibernate.Cfg.Configuration.AddDocumentThroughQueue(NamedXmlDocument docum
ent)
à NHibernate.Cfg.Configuration.AddXmlReader(XmlTextReader hbmReader, String n
ame)
à NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String n
ame)
à NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly)
à NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly)
à NHibernate.Cfg.Configuration.AddAssembly(String assemblyName)
à NHibernate.Cfg.Configuration.DoConfigure(XmlDocument doc)
à NHibernate.Cfg.Configuration.Configure(XmlTextReader reader)
à NHibernate.Cfg.Configuration.Configure(String fileName)
à NHibernate.Cfg.Configuration.Configure()
à adecco.NHibernateHelper..cctor() dans D:\Mes Documents\Visual Studio 2008\P
rojects\adecco\adecco\NHibernateHelper.cs:ligne 22
--- Fin de la trace de la pile d'exception interne ---
à adecco.NHibernateHelper.GetCurrentSession()
à adecco.Manager.ContratManager..ctor() dans D:\Mes Documents\Visual Studio 2
008\Projects\adecco\adecco\Manager\ContratManager.cs:ligne 19
à adecco.Program.Main(String[] args) dans D:\Mes Documents\Visual Studio 2008
\Projects\adecco\adecco\Program.cs:ligne 33



L'application est fermée!
Enfin, je n'arrive pas a mapper le fait que dans contrat j'ai une clef primaire composé avec deux attributs qui sont clf étrangère pour contrat...

J'essai de regarder sur cette page, mais j'ai beau tout essayer, y'a rien qui marche ::
http://www.hibernate.org/hib_docs/v3...irectional-121

Cordialement.