-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: one-to-many association
PostPosted: Wed Aug 01, 2012 6:02 am 
Newbie

Joined: Wed Aug 01, 2012 5:51 am
Posts: 8
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 !


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.