Hello,
i'd like to get from my HQL request 50 Automates and for each, fetch their collection of Anomalie, Indispo and Connexion.
(Spring Batch Reader)
VueAutomateED mapping :
Code:
<class name="com.mycompany.entity.VueAutomateED" table="VUEAUTOMATE">
<id name="id" type="long">
<column name="ID" precision="22" scale="0" />
<generator class="sequence">
<param name="sequence">SEQ_AUTOMATE</param>
</generator>
</id>
<property name="numSerie" type="string">
<column name="NUM_SERIE" length="8" />
</property>
<property name="id_auto_complet" type="string">
<column name="ID_AUTO_COMPLET" length="15" />
</property>
<many-to-one name="entiteED" class="com.mycompany.entity.EntiteED" fetch="select">
<column name="ENTITE_ID" precision="22" scale="0" />
</many-to-one>
<many-to-one name="generationAutomateED" class="com.mycompany.entity.GenerationAutomateED" fetch="select">
<column name="GENERATION_AUTOMATE_ID" precision="22" scale="0" />
</many-to-one>
<set name="tempIndispos" inverse="true" >
<key>
<column name="AUTOMATE_ID" precision="22" scale="0" />
</key>
<one-to-many class="com.mycompany.entity.TempIndispoED" />
</set>
<set name="listHistoAnomalies" inverse="true" >
<key>
<column name="AUTOMATE_ID" precision="22" scale="0" />
</key>
<one-to-many class="com.mycompany.entity.HistoAnomalieED" />
</set>
<set name="listHistoIndispos" inverse="true" >
<key>
<column name="AUTOMATE_ID" precision="22" scale="0" />
</key>
<one-to-many class="com.mycompany.entity.HistoIndispoED" />
</set>
<set name="listConnexions" inverse="true" >
<key>
<column name="AUTOMATE_ID" precision="22" scale="0" />
</key>
<one-to-many class="com.mycompany.entity.ConnexionED" />
</set>
</class>
this Request works fine with only 1 automate (a.id = 30841), collections are well populated.
this request wont work with 2 or more automates (a.id = 30841 or a.id = 30842), first objet's collection are ok, but second collection only contains 1 element.
HQL :
Code:
from VueAutomateED a
join fetch a.generationAutomateED gen
join fetch gen.modeleAutomateED mod
join fetch mod.modes
join fetch a.entiteED ent
left join fetch a.listHistoAnomalies ano
join fetch ano.anomalie
left join fetch a.listConnexions connex
left join fetch a.listHistoIndispos indispos
where to_char(ano.dateDebutAnomalie,'YYYYMMDD') <= '#{jobParameters[dateFinPlage]}'
and to_char(ano.dateFinAnomalie,'YYYYMMDD') >= '#{jobParameters[dateDebutPlage]}'
and (mod.libelle = '#{jobParameters[modeleAutomate]}')
and (a.id = 30842 or a.id = 30841)
order by a.id
Generated SQL :
Code:
select
vueautomat0_.ID as ID3_0_,
generation1_.ID as ID8_1_,
modeleauto2_.ID as ID9_2_,
modeexecut4_.ID as ID13_3_,
entiteed5_.ID as ID12_4_,
listhistoa6_.ID as ID5_5_,
anomalieed7_.ID as ID4_6_,
listconnex8_.ID as ID1_7_,
listhistoi9_.ID as ID7_8_,
vueautomat0_.NUM_SERIE as NUM2_3_0_,
vueautomat0_.ID_AUTO_COMPLET as ID3_3_0_,
vueautomat0_.ENTITE_ID as ENTITE4_3_0_,
vueautomat0_.GENERATION_AUTOMATE_ID as GENERATION5_3_0_,
generation1_.LIBELLE as LIBELLE8_1_,
generation1_.CODE_TYPE_ACORES as CODE3_8_1_,
generation1_.MODELE_AUTOMATE_ID as MODELE4_8_1_,
modeleauto2_.LIBELLE as LIBELLE9_2_,
modeexecut4_.LIBELLE as LIBELLE13_3_,
modes3_.modele_id as modele1_0__,
modes3_.mode_id as mode2_0__,
entiteed5_.LIBELLE as LIBELLE12_4_,
entiteed5_.CODE_REGATE as CODE3_12_4_,
listhistoa6_.DATE_DEBUT as DATE2_5_5_,
listhistoa6_.AUTOMATE_ID as AUTOMATE3_5_5_,
listhistoa6_.DATE_FIN as DATE4_5_5_,
listhistoa6_.ANOMALIE_ID as ANOMALIE5_5_5_,
listhistoa6_.AUTOMATE_ID as AUTOMATE3_1__,
listhistoa6_.ID as ID1__,
anomalieed7_.LIBELLE as LIBELLE4_6_,
anomalieed7_.CODE_EVENEMENT as CODE3_4_6_,
anomalieed7_.RESPONSABILITE_ID as RESPONSA4_4_6_,
anomalieed7_.MODE_EXECUTION_ID as MODE5_4_6_,
anomalieed7_.MODELE_AUTOMATE_ID as MODELE6_4_6_,
listconnex8_.AUTOMATE_ID as AUTOMATE2_1_7_,
listconnex8_.DATE_CONNEXION_SUPERVISION as DATE3_1_7_,
listconnex8_.DATE_INTEGRATION_SUPERVISION as DATE4_1_7_,
listconnex8_.DATE_DECONNEXION_SUPERVISION as DATE5_1_7_,
listconnex8_.AUTOMATE_ID as AUTOMATE2_2__,
listconnex8_.ID as ID2__,
listhistoi9_.DATE_DEBUT as DATE2_7_8_,
listhistoi9_.DATE_FIN as DATE3_7_8_,
listhistoi9_.INDISPONIBILITE_ID as INDISPON4_7_8_,
listhistoi9_.AUTOMATE_ID as AUTOMATE5_7_8_,
listhistoi9_.AUTOMATE_ID as AUTOMATE5_3__,
listhistoi9_.ID as ID3__
from
VUEAUTOMATE vueautomat0_
inner join
GENERATIONS_AUTOMATES generation1_
on vueautomat0_.GENERATION_AUTOMATE_ID=generation1_.ID
inner join
MODELES_AUTOMATES modeleauto2_
on generation1_.MODELE_AUTOMATE_ID=modeleauto2_.ID
inner join
MODE_MODELE modes3_
on modeleauto2_.ID=modes3_.modele_id
inner join
MODES_EXECUTION modeexecut4_
on modes3_.mode_id=modeexecut4_.ID
inner join
ENTITES entiteed5_
on vueautomat0_.ENTITE_ID=entiteed5_.ID
left outer join
HISTORIQUE_ANOMALIES listhistoa6_
on vueautomat0_.ID=listhistoa6_.AUTOMATE_ID
inner join
ANOMALIES anomalieed7_
on listhistoa6_.ANOMALIE_ID=anomalieed7_.ID
left outer join
HISTORIQUE_CONNEXIONS listconnex8_
on vueautomat0_.ID=listconnex8_.AUTOMATE_ID
left outer join
HISTORIQUE_INDISPONIBILITES listhistoi9_
on vueautomat0_.ID=listhistoi9_.AUTOMATE_ID
where
to_char(listhistoa6_.DATE_DEBUT, 'YYYYMMDD')<='20110930'
and to_char(listhistoa6_.DATE_FIN, 'YYYYMMDD')>='20110901'
and modeleauto2_.LIBELLE='LISA'
and (
vueautomat0_.ID=30841
or vueautomat0_.ID=30842
)
order by
vueautomat0_.ID
Any help please ?