Hi !
I'm having trouble doing a Criteria association between two Classes (which are linked by a one-to-many association). Is it possible, using "Locomotive" to get the corresponding "ApproGasoil" ?
I tried :
Code:
session = HibernateUtil.currentSession();
         Criteria test = session
         .createCriteria(Locomotive.class)
         .createAlias("approGasoils", "appros");
Let me give you the mapping files for thoses classes :
Locomotive :
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="com.sncf.fret.hibernate">
   <class
      name="Locomotive"
      table="Locomotive"
   >
      <meta attribute="sync-DAO">false</meta>
      <!-- please tell Joe Hudson that the type 'nchar' could not be resolved.. defaulting to java.lang.String -->
      <id
         name="Id"
         type="java.lang.String"
         column="num_locomotive"
      >
         <generator class="native"/>
      </id>
      <!-- please tell Joe Hudson that the type 'nchar' could not be resolved.. defaulting to java.lang.String -->
      <property
         name="Serie"
         column="serie"
         type="java.lang.String"
         not-null="false"
         length="10"
      />
      <!-- please tell Joe Hudson that the type 'nchar' could not be resolved.. defaulting to java.lang.String -->
      <property
         name="NumEuropeen"
         column="num_europeen"
         type="java.lang.String"
         not-null="false"
         length="15"
      />
   
      <set name="ConsoElectriques" inverse="true" lazy="true">
         <key column="num_locomotive"/>
         <one-to-many class="ConsoElectrique"/>
      </set>
      <set name="ApproGasoils" inverse="true" lazy="true">
         <key column="num_locomotive"/>
         <one-to-many class="ApproGasoil"/>
      </set>
      <set name="Circulations" inverse="true" lazy="true">
         <key column="num_locomotive"/>
         <one-to-many class="Circulation"/>
      </set>
      <set name="ConsoGasoils" inverse="true" lazy="true">
         <key column="num_locomotive"/>
         <one-to-many class="ConsoGasoil"/>
      </set>
      <set name="Boitiers" inverse="true" lazy="true">
         <key column="num_locomotive"/>
         <one-to-many class="Boitier"/>
      </set>
   </class>   
</hibernate-mapping>
ApproGasoil
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="com.sncf.fret.hibernate">
   <class
      name="ApproGasoil"
      table="Appro_gasoil"
   >
      <meta attribute="sync-DAO">false</meta>
      <id
         name="Id"
         type="integer"
         column="id_appro_gasoil"
      >
         <generator class="native"/>
      </id>
      <!-- please tell Joe Hudson that the type 'nchar' could not be resolved.. defaulting to java.lang.String -->
      <property
         name="Lieux"
         column="Lieux"
         type="java.lang.String"
         not-null="false"
         length="30"
      />
      <property
         name="Date"
         column="Date"
         type="timestamp"
         not-null="false"
         length="23"
      />
      <property
         name="Quantite"
         column="Quantite"
         type="integer"
         not-null="false"
         length="10"
      />
      <many-to-one
         name="NumEngin"
         column="NumEngin"
         class="Locomotive"
         not-null="false"
      >
      </many-to-one>
   </class>   
</hibernate-mapping>
Thanks !