I have 3 classes with the corresponding relationship parent child on them:
//SigTcContraloriaObjetivos, SigTcContraloriaIniciativas, SigTcContraloriaAcciones
<class dynamic-insert="false" dynamic-update="true" mutable="true" name="org.citi.tablero.contraloria.planes.model.db.hibernate.dto.SigTcContraloriaObjetivos" optimistic-lock="version" polymorphism="implicit" select-before-update="false" table="SIG_TC_CONTRALORIA_OBJETIVOS">
<id column="ID_OBJETIVO" name="idObjetivo">
<generator class="sequence">
<param name="sequence">SEQ_SIG_CONTRALORIA_OBJETIVOS</param>
</generator>
</id>
<property column="DESCRIPCION" name="descripcion"/>
<set name="children" inverse="false" cascade="all" lazy="false">
<key column="ID_OBJETIVO"/>
<one-to-many class="SigTcContraloriaIniciativas"/>
</set>
</class>
<class dynamic-insert="false" dynamic-update="true" mutable="true" name="org.citi.tablero.contraloria.planes.model.db.hibernate.dto.SigTcContraloriaIniciativas" optimistic-lock="version" polymorphism="implicit" select-before-update="false" table="SIG_TC_CONTRALORIA_INICIATIVAS">
<id column="ID_INICIATIVA" name="idIniciativa">
<generator class="sequence">
<param name="sequence">SEQ_SIG_CONTRALORIA_INICIATIVA</param>
</generator>
</id>
<property column="DESCRIPCION" name="descripcion"/>
<property column="ID_OBJETIVO" name="idObjetivo" />
<set name="children" inverse="false" cascade="all" lazy="false">
<key column="ID_INICIATIVA"/>
<one-to-many class="SigTcContraloriaAcciones"/>
</set>
</class>
<class dynamic-insert="false" dynamic-update="true" mutable="true" name="org.citi.tablero.contraloria.planes.model.db.hibernate.dto.SigTcContraloriaAcciones" optimistic-lock="version" polymorphism="implicit" select-before-update="false" table="SIG_TC_CONTRALORIA_ACCIONES">
<id column="ID_ACCION" name="idAccion">
<generator class="sequence">
<param name="sequence">SEQ_SIG_CONTRALORIA_ACCIONES</param>
</generator>
</id>
<property column="DESCRIPCION" name="descripcion"/>
<property column="ID_INICIATIVA" name="idIniciativa" />
<property column="ID_ORGANIZACION" name="idOrganizacion" />
</class>
I need a way to select one SigTcContraloriaIniciativa with the associated SigTcContraloriaObjetivo and with the associated SigTcContraloriaAccion
This is the query im using:
String sql = "select distinct p from SigTcContraloriaObjetivos p join p.children c join c.children b where and b.idOrganizacion = 8";
(In the database i only have one SigTcContraloriaAccion with idOrganizacion= 8, so my expected result is one SigTcContraloriaObjetivos with the corresponding SigTcContraloriaIniciativas with the corresponding SigTcContraloriaAccion im selecting)
My problem is when I execute query.list() it returns me one SigTcContraloriaObjetivos (as expected), two SigTcContraloriaIniciativas(Not expected, i only expect one), and two SigTcContraloriasAcciones (only one expected) for each SigTcContraloriaIniciativas
UPDATE:
This is the image of the tables: