I have a Parent/Child relationship and I am trying to eagerly fetch the children from the parent without resorting to several SELECTs. I am using
Code:
final Session session = sessionFactory.getCurrentSession();
final String queryStr = "from TransactiveNodeInterchangeFlow t join fetch t.intervals ti "
+ "order by t.sourceId, ti.sinkId, ti.intervalStartTime asc";
@SuppressWarnings("unchecked")
List<TransactiveNodeInterchangeFlow> signals = session.createQuery(queryStr).list();
return signals;
The problem is that I am getting as many parent objects as there are children, this is, if Parent ID=1 has 10 Children, I end up with 10 Parent Instances all of them with ID=1 and the same Children, instead of having a single Parent object (ID=1)
These are my mapping files
Code:
<hibernate-mapping package="com.pnsgdp.data.dataModel">
<class name="TransactiveNodeInterchangeFlow" table="ETMTRANSMISSIONZONE">
<id name="id" type="long" column="TRANSMISSIONZONEID" />
<property name="sourceId" column="TRANSACTIVECONTROLNODENAME" not-null="true" unique="true"/>
<set name="intervals">
<key column="FROMTRANSMISSIONZONEID" />
<one-to-many class="TransactiveNodeInterchangeFlowInterval" />
</set>
</class>
</hibernate-mapping>
<hibernate-mapping package="com.pnsgdp.data.dataModel">
<class name="TransactiveNodeInterchangeFlowInterval" table="R_TCNODEINTERCHANGEFLOW">
<composite-id>
<key-many-to-one name="parent" column="FROMTRANSMISSIONZONEID" />
<key-property name="sinkId" column="TOTCNODENAME" />
<key-property name="intervalStartTime" column="EFFECTIVETIME" type="com.pnsg.time.hibernate.UTCJDateType" />
</composite-id>
<property name="intervalEndTime" column="TERMINATIONTIME" type="com.pnsg.time.hibernate.UTCJDateType" />
<property name="flow" />
</class>
</hibernate-mapping>
I do not want to use DISTINCT nor OUTER JOINS. It is a very simple master/detail example. What am I missing?
Thanks