Bonjour à tous,

Je reviens encore sur un problème que je rencontre avec Hibernate. Lors de la création de mon application et de la configuration d'Hibernate, celui-ci m'a fabriqué tous les objets et mapping des mes tables contenant une clé primaire classique, SAUF QUE, je dispose d'une table dont la clé primaire est composée de deux clés étrangères.

J'ai trouvé quelques tuto, mais toujours pas de résultat, voici ce que j'ai fait :

1.J'ai crée une classe JAVA tel que Hibernate l'a fait automatiquement mais pour ma table dont la clé primaire est composée :

2. J'ai créé un fichier MaTAble.hbm.xml en écrivant à la main les propriétés du mapping :
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"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
  <class name="domaine.Technicien" table="competencev2" catalog="comptechv2">
      <composite-id name="id" class="CompetenceId">
          <key-property name="id_technicien"/>
          <key-property name="id_technique"/>
      </composite-id>
 
      <property name="note" type="string">
          <column name="note" not-null="true"/>
      </property>
 
      <many-to-one name="id_ft">
          <column name="id_technicien"/>
      </many-to-one>
 
      <many-to-one name="id_technique">
          <column name="id_technique"/>
      </many-to-one>
 
  </class>
 
</hibernate-mapping>
3.J'ai renseigné le fichier de configuration de Hibernate hibernate.cfg.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
26
27
28
29
30
31
32
 
<?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>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/comptechv2</property>
    <property name="hibernate.connection.username">root</property>
    <!--    Affiches les logs sql-->
    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.format_sql">true</property>
    <property name="use_sql_comments">true</property>
    <property name="hibernate.current_session_context_class">thread</property>
    <property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
    <!-- JDBC connection pool (use the built-in) -->
    <property name="connection.pool_size">1</property>
    <!--    Mapping-->
    <property name="hibernate.hbm2ddl.auto">create</property>
    <!--    Fichier à mapper-->
    <!--    <mapping class="domaine/Competencev2"/>-->
    <mapping resource="domaine/Famille.hbm.xml"/>
    <mapping resource="domaine/Responsable.hbm.xml"/>
    <mapping resource="domaine/Localisation.hbm.xml"/>
    <mapping resource="domaine/Technique.hbm.xml"/>
    <mapping resource="domaine/Technicien.hbm.xml"/>
    <mapping resource="domaine/Domaine.hbm.xml"/>
    <mapping resource="domaine/Droit.hbm.xml"/>
    <mapping resource="domaine/Produit.hbm.xml"/>
    <mapping resource="domaine/Competencev2.hbm.xml"/>
  </session-factory>
</hibernate-configuration>
J'utilise Netbeans 7.1 comme IDE, est-il possible de configurer automatiquement le mapping de cette table ? (JPA Controler Classes From Entity Classes) ?

Merci d'avance